通过代码实现RelativeLayout的布局
来源:互联网 发布:ansys15.0软件 编辑:程序博客网 时间:2024/06/06 01:24
一:布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/rl_product_parent" android:background="@drawable/login_bg"> <RelativeLayout android:id="@+id/rl_product_main" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="51dp" > <ImageView android:id="@+id/iv_jiuyingbao" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:src="@drawable/jiuyingbao"/> <ImageView android:id="@+id/iv_zhinengcun" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/iv_jiuyingbao" android:layout_alignTop="@id/iv_jiuyingbao" android:src="@drawable/zhinengcun"/> <ImageView android:id="@+id/iv_diydai" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/iv_zhinengcun" android:layout_toRightOf="@id/iv_jiuyingbao" android:layout_alignBottom="@id/iv_jiuyingbao" android:src="@drawable/diydai"/> <ImageView android:id="@+id/iv_wodezhanghu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/iv_jiuyingbao" android:layout_alignLeft="@id/iv_jiuyingbao" android:layout_alignRight="@id/iv_diydai" android:layout_marginTop="5dp" android:src="@drawable/wodezhanghu"/> <ImageView android:id="@+id/iv_dangmianfu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/iv_wodezhanghu" android:layout_alignLeft="@id/iv_wodezhanghu" android:layout_marginTop="5dp" android:src="@drawable/dangminafu"/> <ImageView android:id="@+id/iv_zhuanzhang" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/iv_dangmianfu" android:layout_alignRight="@+id/iv_wodezhanghu" android:src="@drawable/zhuanzhang"/> </RelativeLayout></RelativeLayout>
二:java代码
rl_product_main = (RelativeLayout) main.findViewById(R.id.rl_product_main);RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(rl_product_main.getLayoutParams());//说明当前相对布局距离父控件的顶部100像素,注意是像素rparams.topMargin = 100;//宽高是包裹内容rparams.width = RelativeLayout.LayoutParams.WRAP_CONTENT;rparams.height = RelativeLayout.LayoutParams.WRAP_CONTENT;/** * 一个参数的方法:addRule (int verb) * 给当前相对布局添加一个布局规则,即一些属性等,但是这个布局规则不能涉及到其他兄弟姐妹;或者这个布局规则是一个布尔类型的,设置了即为true,不设置即为false * 两个参数的方法:addRule (int verb, int anchor) * 给当前相对布局添加一个布局规则,这个布局规则可以涉及到其它兄弟姐妹元素,此时第二个参数即为所涉及到的兄弟姐妹的id;或者这个布局规则是一个布尔类型的,此时 * 第二个参数即为RelativeLayout.TRUE代表为true或者0代表为false */rparams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);rl_product_main.setLayoutParams(rparams);
0 0
- 通过代码实现RelativeLayout的布局
- 代码实现 RelativeLayout布局
- RelativeLayout代码实现相对布局
- android 使用代码实现 RelativeLayout布局!
- android 使用代码实现 RelativeLayout布局
- Android使用代码实现RelativeLayout,LinearLayout布局
- android 使用代码实现 RelativeLayout布局
- Android使用代码实现RelativeLayout,LinearLayout布局
- Android使用代码实现RelativeLayout,LinearLayout布局
- android 使用代码实现 RelativeLayout布局
- android 使用代码实现 RelativeLayout布局
- Android使用代码实现RelativeLayout,LinearLayout布局
- android 使用代码实现 RelativeLayout布局
- 纯代码RelativeLayout实现右上角布局
- RelativeLayout进行纯代码布局的理论基础
- 代码布局relativeLayout的位置设置
- 代码布局relativeLayout
- RelativeLayout代码布局
- sqlserver 分页查询总结
- LeetCode203:Remove Linked List Elements
- Java Synchronized与wait notify 连用-2 简化版
- Baidu Map API 学习历程
- POST请求
- 通过代码实现RelativeLayout的布局
- JXL Excel模版下载[列合并](2)
- apache相关配置问题
- 【模板整合】SAM后缀自动机的构建
- Android Exception : JAVA_HOME is set to an invalid directory
- 使用fiddler的断点调试抓包修改请求和响应
- 期望和方差
- [LeetCode] Product of Array Except Self
- 小白学Python(二) 基本文件操作