安卓UI设计
一、线性布局
1.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="cn.edu.bzu.a18lab02.text1Activity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="#666666" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="#0000FF" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="#00FF00" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="#FF0000" />
</LinearLayout>
2.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="cn.edu.bzu.a18lab02.text1Activity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To"
android:layout_weight="1"
android:textColorHint="#ffff00"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject"
android:layout_weight="1"
android:textColorHint="#ffff00"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:gravity="top"
android:text="Message"
android:textColorHint="#ffff00"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:layout_weight="1"/>
</LinearLayout>
二、相对布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_text1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.edu.bzu.a18lab02.text1Activity" > <ImageButton android:id="@+id/button1" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/smile1" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <ImageButton android:id="@+id/button3" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/rabbit1" android:layout_alignTop="@+id/button1" android:layout_toLeftOf="@+id/button1" android:layout_toStartOf="@+id/button1" android:layout_marginLeft="42dp" android:layout_marginEnd="42dp" /> <ImageButton android:id="@+id/button2" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/rabbit3" android:layout_above="@+id/button1" android:layout_alignLeft="@+id/button1" android:layout_alignStart="@+id/button1" android:layout_marginBottom="40dp" /> <ImageButton android:id="@+id/button5" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/rabbit4" android:layout_marginTop="37dp" android:layout_below="@+id/button1" android:layout_alignLeft="@+id/button1" /> <ImageButton android:id="@+id/button4" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/rabbit2" android:layout_alignTop="@+id/button1" android:layout_toRightOf="@+id/button1" android:layout_toEndOf="@+id/button1" android:layout_marginLeft="34dp" android:layout_marginStart="34dp" /> </RelativeLayout>
三、表格布局
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false"> <TableRow android:orientation="vertical"> <TextView android:text="Account:" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_column="0" /> <EditText android:text="Input your account" android:layout_column="1" android:shrinkColumns="0,2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow> <TextView android:text="Password:" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:layout_span="0" android:ems="10" android:id="@+id/editText" /> </TableRow> <Button android:text="Login"/> </TableLayout>