LinearLayout和RelativeLayout的使用
来源:互联网 发布:java捕获异常机制 编辑:程序博客网 时间:2024/06/06 18:50
使用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" 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>
0 0
- LinearLayout和RelativeLayout的使用
- android linearLayout 和 RelativeLayout使用的注意事项
- LinearLayout和RelativeLayout的比较
- linearLayout 和 relativeLayout的区别
- RelativeLayout和LinearLayout的属性
- Android中LinearLayout和RelativeLayout使用详解
- linearLayout 和 relativeLayout的属性区别
- LinearLayout 和 RelativeLayout的属性对比
- linearLayout 和 relativeLayout的属性区别
- linearLayout 和 relativeLayout的属性区别
- LinearLayout和RelativeLayout的属性差异
- linearLayout 和 relativeLayout的属性区别
- linearLayout 和 relativeLayout的属性区别(转)
- 【转】linearLayout 和 relativeLayout的属性区别
- LinearLayout和RelativeLayout的特殊属性
- linearLayout 和 relativeLayout的属性区别
- LinearLayout,RelativeLayout和UI优化的总结
- android的常用布局LinearLayout和RelativeLayout
- eclipse的简单使用及注意点
- 学习笔记之——Android状态栏微技巧,带你真正理解沉浸式模式
- 五个问题
- SoapUI5.0创建WebService接口模拟服务端
- python类私有属性
- LinearLayout和RelativeLayout的使用
- escape 和 unescape使用
- 5.1 mxc_v4l2_capture.c应用程序追踪分析
- 数学
- CSS菜鸟级错误——类别选择器
- 火车站买票问题(poj 2828)
- Apache Commons Configuration
- UVALive 6692 Lucky Number (思路 + 枚举)
- MD5加密算法 字符串的处理