LinearLayout和RelativeLayout 比较

LinearLayout和RelativeLayout

共有属性
java代码中通过btn1关联次控件
android:id="@+id/btn1"

控件宽度
android:layout_width="80px" <wbr><wbr><wbr> //"80dip"或"80dp"<br>android:layout_width =“wrap_content”<br>android:layout_width =“match_parent” <wbr><wbr><br><br>控件高度<br>android:layout_height="80px" <wbr><wbr><wbr> //"80dip"或"80dp"<br>android:layout_height =“wrap_content”<br>android:layout_height =“match_parent” <wbr><br><br>控件排布<br>android:orientation="horizontal”<br>android:orientation="vertical“<br><br>控件间距<br>android:layout_marginLeft="5dip" <wbr><wbr><wbr><wbr><wbr> //距离左边<br>android:layout_marginRight="5dip" <wbr><wbr><wbr><wbr><wbr> //距离右边<br>android:layout_marginTop="5dip" <wbr><wbr><wbr><wbr><wbr> //距离上面<br>android:layout_marginRight="5dip" <wbr><wbr><wbr><wbr><wbr> //距离下面</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

android:paddingLeft="5dip"


控件显示位置
android:gravity="center" <wbr><wbr><wbr> //left,right, top, bottom<br>android:gravity="center_horizontal"<br><br>android:layout_gravity是本元素对父元素的重力方向。<br>android:layout_gravity属性则设置控件本身相对于父控件的显示位置<br>android:gravity是本元素所有子元素的重力方向。<br><br>android:layout_gravity="center_vertical"<br>android:layout_gravity="left"<br>android:layout_gravity="left|bottom"<br><br><br>TextView中文本字体<br>android:text="@String/text1" <wbr><wbr><wbr> //在string.xml中定义text1的值<br>android:textSize="20sp"<br>android:textColor=”#ff123456”<br>android:textStyle="bold" <wbr><wbr><wbr> //普通(normal), 斜体(italic),粗斜体(bold_italic)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

TextView中,控制其以...结束

android:ellipsize="end"

只有一行

android:singleLine="true"

定义控件是否可见
android:visibility=”visible” <wbr><wbr><wbr><wbr> //可见<br>android:visibility=”invisible”  //不可见,但是在布局中占用的位置还在<br>android:visibility=”gone”   //不可见,完全从布局中消失<br><br>定义背景图片<br>android:background="@drawable/img_bg" <wbr><wbr><wbr> //img_bg为drawable下的一张图片<br><br>seekbar控件背景图片及最大值<br>android:progressDrawable="@drawable/seekbar_img" <wbr><wbr><br>android:thumb="@drawable/thumb" <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><br>android:max = "60"<br><br>android:layout_alignWithParentIfMissing<wbr>="true"<br><br><strong><span style="font-size:24px;color:#ff0000;">仅在RelativeLayout中有效</span></strong>:<br>在父亲布局的相对位置<br>android:layout_alignParentLeft="true" <wbr><wbr><wbr><wbr> //在布局左边<br>android:layout_alignParentRight="true" <wbr><wbr><wbr> //在布局右边<br>android:layout_alignParentTop="true" <wbr><wbr><wbr><wbr> //在布局上面<br>android:layout_alignParentBottom="true " <wbr> //在布局的下面<br><br>在某个控件的相对位置<br>android:layout_toRightOf="@id/button1" <wbr> //在控件button1的右边,不仅仅是紧靠着<br>android:layout_toLeftOf="@id/button1" <wbr><wbr> //在控件button2的左边,不仅仅是紧靠着<br>android:layout_below="@id/button1 " <wbr><wbr><wbr><wbr> //在控件button1下面,不仅仅是正下方<br>android:layout_above=“@id/button1” <wbr><wbr> //在控件button1下面,不仅仅是正下方<br><br>定义和某控件对奇<br>android:layout_alignTop=”@id/button1” <wbr> //和控件button1上对齐<br>android:layout_alignBottom=”@id/button1” <wbr> //和控件button1下对齐<br>android:layout_alignLeft=”@id/button1” <wbr> //和控件button1左对齐<br>android:layout_alignRight=”@id/button1” <wbr> //和控件button2右对齐<br><br><br>android:layout_centerHorizontal="true" <wbr><wbr><wbr><wbr><wbr><wbr> //水平居中<br>android:layout_centerVertical="true"<br>android:layout_centerInParent="true" <wbr><br><br><strong><span style="font-size:24px;color:#ff0000;">仅在LinearLayout中有效<br></span></strong>设置控件在一排或一列中所占比例值<br>android:layout_weight="1"</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值