標籤:
第一種:線性布局
這種布局相對是比較簡單的,要麼豎向排列,要麼橫向排列
[html] view plaincopy
<?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:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Type"/>
<EditText
android:id="@+id/et_entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hello"
android:background="#ffffff"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/OK"/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel"/>
</LinearLayout>
效果如下:
第二種:相對布局
相對布局:即相對於一個參照物的位置,那麼必須先有參照物,才能確定接下來的控制項的位置,例如先有A,然後B相對於A,在A的右邊、下邊或者什麼位置。當然android中也可以相對於父表單。
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="100dp" 5 tools:context=".MainActivity"> 6 <TextView 7 android:id="@+id/tv_title" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content" 10 android:layout_marginLeft="10dp"11 android:layout_marginTop="10dp" 12 android:textColor="#660000"13 android:textSize="20sp"14 android:text="我是大的文本" /> 15 <TextView 16 android:layout_below="@id/tv_title" 17 android:layout_width="wrap_content" 18 android:layout_height="wrap_content" 19 android:layout_marginLeft="10dp" 20 android:layout_marginTop="10dp" 21 android:textColor="#660000" 22 android:textSize="14sp" 23 android:text="我是小的文本" /> 24 <CheckBox 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:layout_alignParentLeft="true" 28 android:layout_centerVertical="true"29 />30 </RelativeLayout>
這個布局如所示:
第三種:表格版面配置
[html] view plaincopy
-
表格版面配置:比如幾行幾列的格式,例如excel的樣子
[html] view plaincopy
- <?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:background="#000000"
- android:stretchColumns="1" >
- <TableRow >
- <TextView
- android:text="姓名"
- android:padding="10dip"
- android:textColor="#ffffff"/>
- <EditText
- android:layout_marginLeft="20dp"
- android:background="#ffffff"
- />
- </TableRow>
- <TableRow >
- <TextView
- android:text="密碼"
- android:padding="10dip"
- android:textColor="#ffffff"/>
- <EditText
- android:layout_marginLeft="20dp"
- android:background="#ffffff"
- android:password="true"
- />
- </TableRow>
-
- </TableLayout>
效果如下:
第四種:幀布局
幀布局:其實比較簡單的理解就是,一個圖片疊加到一個圖片的上面,就是圖片的疊加
[html] view plaincopy
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center"
- android:background="#ff0000" />
-
- <TextView
- android:layout_width="250dp"
- android:layout_height="390dp"
- android:layout_gravity="center"
- android:background="#dd0000" />
- <TextView
- android:layout_width="180dp"
- android:layout_height="300dp"
- android:layout_gravity="center"
- android:background="#bb0000" />
- <TextView
- android:layout_width="110dp"
- android:layout_height="210dp"
- android:layout_gravity="center"
- android:background="#990000" />
- <TextView
- android:layout_width="40dp"
- android:layout_height="120dp"
- android:layout_gravity="center"
- android:background="#770000" />
- </FrameLayout>
效果如下:
好了,擊中常見的布局方式就介紹完了,這些也是自己在看代碼的過程中摸索出來的,希望對自己,對別人會有所協助
android基本布局