用代码设置 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分辨出是来自别人说的还是自己说的.那么须要对本身 ...
随机推荐
- C/C++实现bmp文件读写
之前知道点bmp图的格式,然后对8位操作过,然后今天弄了一下24位真彩色的. C++读取.旋转和保存bmp图像文件编程实现 主要是理解bmp文件的格式8/24位的区别 8位图有调色板,24位在文件头和 ...
- 怎样更好的设计你的REST API之基于REST架构的Web Service设计及REST框架实现
一.REST 含状态传输(英文:Representational State Transfer,简称REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格. 眼下在 ...
- 【iOS系列】-UITableViewCell的展开与收缩的实现思路
UITableViewCell的展开与收缩的实现思路 现在项目中很多地方都会用到,所以我这里介绍一种可以复用的思路,这与文章后面的Swift的实现思路不同,具体大家可自行对比. Demo项目地址 开始 ...
- Java正则表达式的用法
/** * 校验时间格式,正确则返回true * @param xxx * @return */ private static boolean checkDateFormat (String xxx) ...
- Basic Queries (LINQ to XML)
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-queries-linq-to ...
- YTU 2904: B--Faultfinding
2904: B--Faultfinding 时间限制: 1 Sec 内存限制: 128 MB 提交: 64 解决: 33 题目描述 Do you remember the game in whic ...
- Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(VSM)
Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(V 时间:2010-04-12 16:06来源:SilverlightChina. ...
- BZOJ 1305:dance跳舞(二分+最大流)
一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会“单向喜欢”).每个男孩 ...
- Python 函数定义以及参数传递
Python 函数定义以及参数传递1.函数定义#形如def func(args...): doSomething123以关键字def 开头,后面是函数名和参数下面是函数处理过程. 举例: def ad ...
- http_load常见问题及解决方案
1.错误信息:byte count wrong http_load在处理时会去关注每次访问同一个URL返回结果(即字节数)是否一致,若不一致就会抛出byte count wrong 所以动态页面可以忽 ...