LinearLayout和RelativeLayout的使用
2016-08-23 19:36
246 查看
使用LinearLayout实现下图的界面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <!-- 第一层 1 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ff0000" android:orientation="vertical" > <!-- 第二层 1 horizontal --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#00ff66" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:background="#ff0066" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#0066ff" /> </LinearLayout> <!-- 第二层 1 horizontal --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#ff8866" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#33ff66" /> </LinearLayout> </LinearLayout> <!-- 第一层 2 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:background="#0000ff" android:orientation="horizontal" > <!-- 垂直的线性布局分成两部分 --> <!-- 第一部分 --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:background="#0000ff" android:orientation="vertical" > <!-- 里面有两行 --> <!-- 第一行 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#0000ff" android:orientation="horizontal" > <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#448811" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:background="#ff9900" /> </LinearLayout> <!-- 第二行 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ffff" android:orientation="vertical" > </LinearLayout> </LinearLayout> <!-- 第二部分 --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#0000ff" android:orientation="vertical" > </LinearLayout> </LinearLayout> <!-- 第一层 1 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ff00" android:orientation="vertical" > <!-- 第一层的第一层 1 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#33ff00" android:orientation="vertical" > <!-- 第一层的第一层(1) 1 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" b066 android:background="#ffff00" android:orientation="horizontal" > <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#ff8866" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:background="#33ff66" /> </LinearLayout> </LinearLayout> <!-- 第一层的第二层 1 --> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ffff00" android:orientation="vertical" > </LinearLayout> </LinearLayout> </LinearLayout>
Layout实现下图的界面
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 50dp的TextView --> <TextView android:id="@+id/tv1" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <TextView android:id="@+id/tv2" android:layout_below="@id/tv1" android:layout_toRightOf="@id/tv1" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <TextView android:id="@+id/tv3" android:layout_below="@id/tv2" android:layout_toRightOf="@id/tv2" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <TextView android:id="@+id/tv4" android:layout_below="@id/tv3" android:layout_toLeftOf="@id/tv3" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <TextView android:id="@+id/tv5" android:layout_below="@id/tv4" android:layout_toLeftOf="@id/tv4" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <TextView android:id="@+id/tv6" android:layout_below="@id/tv4" android:layout_toRightOf="@id/tv4" android:layout_width="50dp" android:layout_height="50dp" android:background="#66ff66" android:text=" " /> <!-- 20dp的TextView --> <TextView android:layout_alignTop="@id/tv2" android:layout_toRightOf="@id/tv2" android:layout_width="20dp" android:layout_height="20dp" android:background="#9900ff" android:text=" " /> <TextView android:layout_alignBottom="@id/tv2" android:layout_toLeftOf="@id/tv2" android:layout_width="20dp" android:layout_height="20dp" android:background="#9900ff" android:text=" " /> <TextView android:layout_alignBottom="@id/tv3" android:layout_toRightOf="@id/tv3" android:layout_width="20dp" android:layout_height="20dp" android:background="#9900ff" android:text=" " /> <TextView android:layout_alignLeft="@id/tv5" android:layout_above="@id/tv5" android:layout_width="20dp" android:layout_height="20dp" android:background="#9900ff" android:text=" " /> <TextView android:layout_alignRight="@id/tv6" android:layout_below="@id/tv6" android:layout_width="20dp" android:layout_height="20dp" android:background="#9900ff" android:text=" " /> </RelativeLayout>
相关文章推荐
- Android中LinearLayout、RelativeLayout、TableLayout、AbsoluteLayout容器的使用
- android linearLayout 和 RelativeLayout使用的注意事项
- 点击textview 使用selector改变对应viewGroup(LinearLayout,RelativeLayout)的背景
- Android中LinearLayout、RelativeLayout、TableLayout、AbsoluteLayout容器的使用
- 使用RelativeLayout还是LinearLayout?
- 用android LinearLayout和RelativeLayout实现精确布局
- 用android LinearLayout和RelativeLayout实现精确布局(转)很适合新人看
- android LinearLayout和RelativeLayout实现精确布局
- linearLayout 和 relativeLayout的属性区别
- android LinearLayout和RelativeLayout实现精确布局
- 关于linearLayout的中 android:layout_weight 的使用
- linearLayout 和 relativeLayout的属性区别
- android LinearLayout和RelativeLayout实现精确布局
- 浅谈Android五大布局——LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout
- (转)浅谈Android五大布局——LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout和TableLayout
- (转)用android LinearLayout和RelativeLayout实现listView的listItem布局
- 对android LinearLayout中layout_weight属性使用
- android LinearLayout和RelativeLayout实现精确布局
- 对android LinearLayout中layout_weight属性使用初探
- android LinearLayout和RelativeLayout实现精确布局