布局分4種:
1. LinearLayout (線性布局)
file:///H:/tool/01/Android/android-sdk-windows/docs/guide/topics/ui/layout/linear.html
事例代碼:
2. RelativeLayout (相對布局)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView
android:id="@+id/numbeLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/number" />
<EditText
android:id="@+id/number2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@null"
android:layout_below="@id/numbeLabel" //這里表示這個控件顯示在id為numberLabel這個控件下面
/>
<Button
android:id="@+id/ok"
android:text="@string/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/number2"
android:layout_alignParentRight="true" //這里表示這個控件在父對象里面是居右顯示
android:layout_marginLeft="10px" //這里表示這個控件跟左邊這個控制的間距是10像素
/>
<Button
android:text="@string/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok" //表示顯示在ok這個按鈕左邊
android:layout_alignTop="@id/ok" //表示與ok這個按鈕,頂對齊
/>
</RelativeLayout>
3. TableLayout (表格布局)
4. FrameLayout (幀布局)
就像gif圖片一樣,或者可以理解成層,可以疊加在一起
<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/bofangtwo"
android:contentDescription="@string/app_name"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bofang"
android:contentDescription="@string/app_name"
android:layout_gravity="center"
/>
</FrameLayout>
注意:在寫
android:src="@drawable/bofang"的時候,注意圖片后面的擴展名不要帶,帶上就會出錯!
把bofang.png和bofangtwo.jpg復制到res中的drawable-hdpi中
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。