赞
踩
1.相对布局管理器,是需要有一个参考对象来进行布局的管理器,首先要有一个参考的组件,例如父类桌面的顶部,左部,右部,底部,或者相对于同级元素的任意位置
2.相对布局非常强大,它可以消除嵌套试图组,并使布局层次结构保持扁平化,从而提高性能,多层嵌套的LinearLayout可以用一个LinearLayout替换
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
属性列表
<LinearLayout >
起始标签后边是固定格式为XML命名空间属性
<!-- 在容器的中央 -->
<Button
android:id="@+id/bt1" `设置id`
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" `取值:true,false`
android:text="firstButton"
android:textColor="#ff0000"
/>
<!-- 在容器的中央 --> <Button android:id="@+id/bt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="firstButton" android:textColor="#ff0000" /> <!-- 在firstButton左边 --> <Button android:id="@+id/bt2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" `保持同一水平线,默认去顶部` android:layout_toStartOf="@id/bt1" `相对的控件的id` android:text="secondButton" android:textColor="#00ff00" />
<TextView android:id="@+id/text_v1" android:layout_width="300dp" android:layout_height="300dp" android:text="hhh" android:background="#0000ff" android:layout_centerHorizontal="true" `相对父类水平居中` /> <LinearLayout `嵌套线性布局` android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" `线性布局里遵从水平` android:layout_below="@id/text_v1" android:layout_centerHorizontal="true" `线性布局里遵从父容器居中` > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bt1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bt2" /> </LinearLayout>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。