android:layout_width只能设置fill_parent(横向填充整个屏幕)或wrap_content(横向填充控件本身大小)
android:width设置具体控件的横向大小 单位是像素
FrameLayout, LinearLayout , AbsoluteLayout, RelativeLayout, TableLayout.
----- FrameLayout-----
Demo1:
activity_main.xml
ok
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:inputType="textPassword" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world" tools:context=".MainActivity" /> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/hello" android:textColor="#0000ff" android:textColorHighlight="#aaaaaa" android:textSize="20dp" android:textStyle="bold" tools:context=".MainActivity" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/world" android:textColor="#333333" android:textStyle="italic" tools:context=".MainActivity" /> </FrameLayout>
res/values/目录下的xml文件中设置@string对应的value
----------
??
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/movie" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/play" android:layout_gravity="center" /> </FrameLayout>
movie 和 play 是res/drawable目录下对应的图片文件名
----- LinearLayout(线性布局)-----
----
-----AbsoluteLayout(绝对布局)----
----
----
----
---- RelativeLayout(相对布局) -----
----
----
----
----- TableLayout(表格布局) -----
----
----
----
----
----