用代码设置 RelativeLayout.LayoutParams
1.注意
- 不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为 ALIGN_PARENT_BOTTOM。
- 如果parent是
wrap_content
的话,alignParentRight
就意味着要求parent的layout_width="match_parent"
;alignParentBottom
就意味着要求parent的layout_height="match_parent"
等等。
2.用代码设置 RelativeLayout.LayoutParams
RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) holder.layout.getLayoutParams(); //如果之前设置了rule,同时设置了多个rules可能冲突,下面代码清空rules
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){// >= 17
params3.removeRule(RelativeLayout.RIGHT_OF);
}else{
int rules[] = params3.getRules();
rules[RelativeLayout.LEFT_OF] = ;
rules[RelativeLayout.RIGHT_OF] = ;
}
//添加新的rules,一般刚创建RelativeLayout.LayoutParams时,不要添加任何rule
if (mb.contact.isSelf()) {
params3.addRule(RelativeLayout.LEFT_OF,R.id.msg_portrait);
}else{
params3.addRule(RelativeLayout.RIGHT_OF,R.id.msg_portrait);
}
holder.layout.setLayoutParams(params3);
3.常用的rule
/**
* Rule that aligns a child's right edge with another child's left edge.
*/
public static final int LEFT_OF = ;
/**
* Rule that aligns a child's left edge with another child's right edge.
*/
public static final int RIGHT_OF = ;
/**
* Rule that aligns a child's bottom edge with another child's top edge.
*/
public static final int ABOVE = ;
/**
* Rule that aligns a child's top edge with another child's bottom edge.
*/
public static final int BELOW = ; /**
* Rule that aligns a child's baseline with another child's baseline.
*/
public static final int ALIGN_BASELINE = ;
/**
* Rule that aligns a child's left edge with another child's left edge.
*/
public static final int ALIGN_LEFT = ;
/**
* Rule that aligns a child's top edge with another child's top edge.
*/
public static final int ALIGN_TOP = ;
/**
* Rule that aligns a child's right edge with another child's right edge.
*/
public static final int ALIGN_RIGHT = ;
/**
* Rule that aligns a child's bottom edge with another child's bottom edge.
*/
public static final int ALIGN_BOTTOM = ; /**
* Rule that aligns the child's left edge with its RelativeLayout
* parent's left edge.
*/
public static final int ALIGN_PARENT_LEFT = ;
/**
* Rule that aligns the child's top edge with its RelativeLayout
* parent's top edge.
*/
public static final int ALIGN_PARENT_TOP = ;
/**
* Rule that aligns the child's right edge with its RelativeLayout
* parent's right edge.
*/
public static final int ALIGN_PARENT_RIGHT = ;
/**
* Rule that aligns the child's bottom edge with its RelativeLayout
* parent's bottom edge.
*/
public static final int ALIGN_PARENT_BOTTOM = ; /**
* Rule that centers the child with respect to the bounds of its
* RelativeLayout parent.
*/
public static final int CENTER_IN_PARENT = ;
/**
* Rule that centers the child horizontally with respect to the
* bounds of its RelativeLayout parent.
*/
public static final int CENTER_HORIZONTAL = ;
/**
* Rule that centers the child vertically with respect to the
* bounds of its RelativeLayout parent.
*/
public static final int CENTER_VERTICAL = ;
/**
* Rule that aligns a child's end edge with another child's start edge.
*/
public static final int START_OF = ;
/**
* Rule that aligns a child's start edge with another child's end edge.
*/
public static final int END_OF = ;
/**
* Rule that aligns a child's start edge with another child's start edge.
*/
public static final int ALIGN_START = ;
/**
* Rule that aligns a child's end edge with another child's end edge.
*/
public static final int ALIGN_END = ;
/**
* Rule that aligns the child's start edge with its RelativeLayout
* parent's start edge.
*/
public static final int ALIGN_PARENT_START = ;
/**
* Rule that aligns the child's end edge with its RelativeLayout
* parent's end edge.
*/
public static final int ALIGN_PARENT_END = ;
用代码设置 RelativeLayout.LayoutParams的更多相关文章
- 在代码设置RelativeLayout的属性,比如layout_below
( (RelativeLayout.LayoutParams)holder.ivLvDivider.getLayoutParams()).addRule(RelativeLayout.BELOW, R ...
- Android 代码设置RelativeLayout元素居中
RelativeLayout relativeLayout= new RelativeLayout(this); RelativeLayout.LayoutParams rlp=new Relativ ...
- 代码中动态改变布局属性RelativeLayout.LayoutParams.addRule()
我们知道,在 RelativeLayout 布局中有很多特殊的属性,通常在载入布局之前,在相关的xml文件中进行静态设置即可. 但是,在有些情况下,我们需要动态设置布局的属性,在不同的条件下设置不同的 ...
- 在代码中设置RelativeLayout布局中标签的android:layout_toLeftOf、android:layout_toRightOf等属性
需要动态改变RelativeLayout里面控件的相对位置,经一个技术群的群友提示,找到了如下的方法,做下记录: RelativeLayout.Layoutparams params = (Rel ...
- 在代码动态设置RelativeLayout的属性,比如layout_below
( (RelativeLayout.LayoutParams)holder.ivLvDivider.getLayoutParams()).addRule(RelativeLayout.BELOW, R ...
- RelativeLayout.LayoutParams.addRule()方法
1.应用场景 在使用RelativeLayout布局的时候,通常在载入布局之前在相关的XML文件中进行静态设置即可.但是,在有些情况下,我们需要动态的设置布局 的属性,在不同条件下设置不同的布局排列方 ...
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w ...
- Android -- java代码设置margin
我们平常可以直接在xml里设置margin,如: <ImageView android:layout_margin="5dip" android:src="@dra ...
- android 用java代码设置布局、视图View的宽度/高度或自适应
在achat项目中,对话内容的长宽设置为自适应.可是假设文本内容太多,则宽度几乎相同布满,若自己说的和对方说的都非常多内容.则满屏都是文字.则不easy分辨出是来自别人说的还是自己说的.那么须要对本身 ...
随机推荐
- CentOS系统中常用查看系统信息和日志命令小结
转载:http://www.3lian.com/edu/2015/04-09/204628.html 进程 # ps -ef # 查看所有进程 # top # 实时显示进程状态(另一篇文章里面有详细的 ...
- DataGridView依据下拉列表显示数据
我们都知道,DataGridView能够直接绑定数据源.显示数据库中的数据.可是我想做的是能够对他进行条件查询,依据用户级别选择不同级别的记录. 以上这个控件就是DataGridView控件,能够用它 ...
- bufferevent 与 socket
http://blog.sina.com.cn/s/blog_56dee71a0100qx4s.html 很多时候,除了响应事件之外,应用还希望做一定的数据缓冲.比如说,写入数据的时候,通常的运行模式 ...
- soapUI系列之—-03 Groovy脚本常用方法2
------Groovy脚本常用方法 1.解析Json数据脚本 //groovy读取json的方式很简单,re.body.businessinfo.c2rate读取c2rate对应的值 import ...
- 【转】实现LoadRunner多个场景的顺序执行
应用场景假设有3个不同的测试场景,分别为并发登录.核心业务.可靠性测试,3个场景有先后执行顺序.由于白天测试机器另有用处,只能在晚上进行性能测试,这时我们的期望是能否把测试场景都设定好之后晚上自动运行 ...
- C#构造方法(函数) C#方法重载 C#字段和属性 MUI实现上拉加载和下拉刷新 SVN常用功能介绍(二) SVN常用功能介绍(一) ASP.NET常用内置对象之——Server sql server——子查询 C#接口 字符串的本质 AJAX原生JavaScript写法
C#构造方法(函数) 一.概括 1.通常创建一个对象的方法如图: 通过 Student tom = new Student(); 创建tom对象,这种创建实例的形式被称为构造方法. 简述:用来初 ...
- Redis Server分布式缓存编程
这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...
- Unity5.1 新的网络引擎UNET(八) UNET 系统概括
孙广东 2015.7.12 Server and Host 在Unity 的 网络系统,游戏有 一个server和多个client. 当没有专用的server时,client之中的一个扮演s ...
- HLJU 1220: AC100天 (枚举)
1220: AC100天 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 89 Solved: 12 [id=1220">Submit ...
- onDestroy强制退出后,process crash的处理
from http://bbs.9ria.com/thread-248722-1-1.html 一般情况,我们在执行测试的过程中都会调用tearDwon方法,以Robotium为例,我们在te ...