天天看點

android layout / android textsize

Constant Value Description

fill_parent

-1 The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by 

match_parent

.

match_parent

-1 The view should be as big as its parent (minus padding). Introduced in API Level 8.

wrap_content

-2 The view should be only big enough to enclose its content (plus padding).

實質上layout 隻存在了兩種,一種是match_parent, 另一種是 wrap_content. fill_parent 已經被match_parent所取代

-----------------------textsize-------------------------------

http://developer.android.com/training/multiscreen/screendensities.html

 Therefore, when specifying dimensions, always use either 

dp

 or 

sp

 units. A 

dp

 is a density-independent pixel that corresponds to the physical size of a pixel at 160 dpi. An 

sp

 is the same base unit, but is scaled by the user's preferred text size (it’s a scale-independent pixel), so you should use this measurement unit when defining text size (but never for layout sizes).

For example, when you specify spacing between two views, use

dp

 rather than 

px

:

<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/clickme"
    android:layout_marginTop="20dp" />      

When specifying text size, always use 

sp

:

<TextView android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="20sp" />      

dp可以在不同的分辨率下實作實體尺寸“差不多”的效果

sp主要處理文字的大小

繼續閱讀