p; android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="取消"
/>
</LinearLayout>
</LinearLayout>
第二个实例
①效果图:
②核心代码:
mian.xml
- <?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:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1">
-
- <TextView
- android:text="red"
- android:gravity="center_horizontal"
- android:background="#aa0000"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"
- />
- <!--android:gravity="center_horizontal"水平居中 -->
- <!--layout_weight属性以控制各个控件在布局中的相对大小。layout_weight属性是一个非负整数值。
- 线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。
- 例如,在水平布局的LinearLayout中有两个Button,这两个Button的layout_weight属性值都为1,
- 那么这两个按钮都会被拉伸到整个屏幕宽度的一半。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;
- 对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,
- 再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度-->
- <TextView
- android:text="Teal"
- android:gravity="center_horizontal"
- &nb
|