1.线性布局android
线性方向显示它的子视图 水平或者垂直布局
android:orientation="vertical" 表示该布局下的元素垂直排列;
android:orientation="horizontal" 表示该布局水平布局spa
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text= "button1" android:layout_weight="1"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text= "button2" android:layout_weight="1"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text= "button3" android:layout_weight="1"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text= "button4" android:layout_weight="1"/> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text= "button5" android:layout_weight="1"/> </LinearLayout>
视图code
2.相对布局xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text= "here"/> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:text= "肯定"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text= "取消"/> </RelativeLayout>
如图blog
3.随意布局图片
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#4400ff00" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请输入收件人的电话号码"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="phone" android:id="@+id/et_phone"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请输入信息的内容"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:lines="5" android:inputType="textMultiLine" android:id="@+id/et_body"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:lines="5" android:inputType="textMultiLine" android:id="@+id/hello"/> <Button android:id="@+id/hellobutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/default_message"/> </LinearLayout>