標籤:strong log sch 也有 color 表示 wrap ges 沒有
一:LinearLayout
1、線性布局,這個東西,從外框上可以理解為一個div,他首先是一個一個從上往下羅列在螢幕上。每一個LinearLayout裡面又可分為垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )。當垂直布局時,每一行就只有一個元素,多個元素依次垂直往下;水平布局時,只有一行,每一個元素依次向右排列。
linearLayout中有一個重要的屬性 android:layout_weight="1",這個weight在垂直布局時,代表行距;水平的時候代表列寬;weight值越大就越大。
2、TextView佔一定的空間,沒有賦值也有一定的寬高,要特別注意。
第一個執行個體
:
代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="right" > <!-- android:gravity="right"表示Button組件向靠右對齊 --> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="確定" /> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="取消" /> </LinearLayout> </LinearLayout>
第二個執行個體:
:
代碼:
<?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" ><TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="5" android:background="#3C3C3C" /><TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#FFEFD5" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="4" android:background="#66CDAA" android:orientation="horizontal" > <TextView android:id="@+id/txt1" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="#FFF663" android:layout_weight="1" /> <TextView android:id="@+id/txt2" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="#E82917" android:layout_weight="4" /> <TextView android:id="@+id/txt3" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="#FFF663" android:layout_weight="1" /> </LinearLayout></LinearLayout>
我們要做的就是多多實踐,多看下關於軟體的布局。軟體上的布局和真機上的布局有差異,我們儘可能的拿真機去測驗,並且在不同的機型上去測驗。
Android開發--布局