android RelativeLayout属性和使用
来源:互联网 发布:网站seo推广 编辑:程序博客网 时间:2024/06/06 02:43
android RelativeLayout属性和使用, 实现上面view叠加在下面view之上的效果
Android RelativeLayout 属性
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft 左偏移的值;
android:layout_marginRight 右偏移的值;
example:1.
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”
2. 使用RelativeLayout实现叠加的效果上面的view覆盖下面的view。
对任何布局,通过android:layout_marginXXX等属性设置为负值来实现相邻view之间的叠加效果,
例如:
android:layout_marginTop="-50dip" 可实现与相邻的顶端view叠加50dip区域的效果。
但是,谁叠加在谁的上面是由他们在xml文件中的描述顺序决定的, 后出现的会在上面。
因此如果要让布局上面的view覆盖在下面的view之上,不能使用LinearLayout。因为, 对于LinearLayout,在xml文件中的描述view时,必须先描述上方的view,让后描述下方的view,所以下方view的会覆盖在上方view之上。
可以使用RelativeLayout。因为在Relativelayout的布局中,我们可以先描述处于下方的view,后描述上方的view。(注意, 此时先描述的View需要使用后描述的view的ID, 需要使用"@+id/相应的viewID")
例如:下面就是蓝色的button会覆盖绿色button之上的例子
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:layout_below="@+id/bt1" android:layout_above="@+id/bt2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff00ff00" android:layout_marginTop="-50dip"/> <Button android:id="@+id/bt1" android:layout_width="fill_parent" android:layout_height="100dip" android:background="#ff0000ff"/> <Button android:id="@+id/bt2" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="100dip" android:background="#ff0000ff"/></RelativeLayout>
example:2.
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000"> <ImageView android:id="@+id/channellogo" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon"/> <TextView android:id="@+id/startime" android:layout_width="wrap_content" android:textSize="16dp" android:layout_height="wrap_content" android:padding="3dp" android:scrollbars="vertical" android:textColorHighlight="#ff0000ff" android:text="title" android:layout_toRightOf="@+id/channellogo" /> <TextView android:id="@+id/program" android:layout_width="wrap_content" android:textSize="16dp" android:layout_height="wrap_content" android:padding="3dp" android:scrollbars="vertical" android:textColorHighlight="#ffff0000" android:layout_toRightOf="@+id/channellogo" android:text="description" android:layout_below="@+id/startime"/></RelativeLayout>
- android RelativeLayout属性和使用
- android RelativeLayout的属性设置与使用
- android与RelativeLayout和属性学习
- android入门-LinearLayout和RelativeLayout 属性对比
- android RelativeLayout属性和布局实例
- android RelativeLayout 适用场景和属性
- android RelativeLayout常用属性
- Android RelativeLayout 属性
- Android RelativeLayout 属性 (
- Android RelativeLayout常用属性~
- android RelativeLayout布局属性
- Android RelativeLayout 属性大全
- Android-----RelativeLayout属性
- Android RelativeLayout 属性
- Android中Relativelayout属性
- 【android RelativeLayout 常用属性】
- Android RelativeLayout 属性
- Android RelativeLayout 属性
- android系统中获取imei号和其他手机信息
- Android 之 内存管理
- java编程中'为了性能'一些尽量做到的地方
- .net 获取时间常用代码
- jquery笔记
- android RelativeLayout属性和使用
- ubuntu10.10安装VMWare tools
- Android TextView无焦点滚动显示
- windows socket initialization fail解决方法
- soundtouch之变调、变速、节拍
- Android 手势 动画 ViewFlippe (1)
- hash算法设计
- 《定风波》--苏轼
- Android系统构架分析和应用程序目录结构分析