用代码设置 RelativeLayout.LayoutParams

用代码设置 RelativeLayout.LayoutParams1.注意不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为ALIGN_PARENT_BOTTOM。如果parent是wrap_content的话,alignParentRight就意味着要求parent的layout_width=”match_par…

大家好,又见面了,我是你们的朋友全栈君。

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

 1         RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) holder.layout.getLayoutParams();
 2 
 3         //如果之前设置了rule,同时设置了多个rules可能冲突,下面代码清空rules
 4         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
   
   // >= 17
 5             params3.removeRule(RelativeLayout.RIGHT_OF);
 6         }else{
 7             int rules[] = params3.getRules();
 8             rules[RelativeLayout.LEFT_OF] = 0;
 9             rules[RelativeLayout.RIGHT_OF] = 0;
10         }
11         //添加新的rules,一般刚创建RelativeLayout.LayoutParams时,不要添加任何rule
12         if (mb.contact.isSelf()) {
13             params3.addRule(RelativeLayout.LEFT_OF,R.id.msg_portrait);
14         }else{
15             params3.addRule(RelativeLayout.RIGHT_OF,R.id.msg_portrait);
16         }
17         holder.layout.setLayoutParams(params3);

3.常用的rule

 1 /**  2  * Rule that aligns a child's right edge with another child's left edge.  3 */  4 public static final int LEFT_OF = 0;  5 /**  6  * Rule that aligns a child's left edge with another child's right edge.  7 */  8 public static final int RIGHT_OF = 1;  9 /**  10  * Rule that aligns a child's bottom edge with another child's top edge.  11 */  12 public static final int ABOVE = 2;  13 /**  14  * Rule that aligns a child's top edge with another child's bottom edge.  15 */  16 public static final int BELOW = 3;  17  18 /**  19  * Rule that aligns a child's baseline with another child's baseline.  20 */  21 public static final int ALIGN_BASELINE = 4;  22 /**  23  * Rule that aligns a child's left edge with another child's left edge.  24 */  25 public static final int ALIGN_LEFT = 5;  26 /**  27  * Rule that aligns a child's top edge with another child's top edge.  28 */  29 public static final int ALIGN_TOP = 6;  30 /**  31  * Rule that aligns a child's right edge with another child's right edge.  32 */  33 public static final int ALIGN_RIGHT = 7;  34 /**  35  * Rule that aligns a child's bottom edge with another child's bottom edge.  36 */  37 public static final int ALIGN_BOTTOM = 8;  38  39 /**  40  * Rule that aligns the child's left edge with its RelativeLayout  41  * parent's left edge.  42 */  43 public static final int ALIGN_PARENT_LEFT = 9;  44 /**  45  * Rule that aligns the child's top edge with its RelativeLayout  46  * parent's top edge.  47 */  48 public static final int ALIGN_PARENT_TOP = 10;  49 /**  50  * Rule that aligns the child's right edge with its RelativeLayout  51  * parent's right edge.  52 */  53 public static final int ALIGN_PARENT_RIGHT = 11;  54 /**  55  * Rule that aligns the child's bottom edge with its RelativeLayout  56  * parent's bottom edge.  57 */  58 public static final int ALIGN_PARENT_BOTTOM = 12;  59  60 /**  61  * Rule that centers the child with respect to the bounds of its  62  * RelativeLayout parent.  63 */  64 public static final int CENTER_IN_PARENT = 13;  65 /**  66  * Rule that centers the child horizontally with respect to the  67  * bounds of its RelativeLayout parent.  68 */  69 public static final int CENTER_HORIZONTAL = 14;  70 /**  71  * Rule that centers the child vertically with respect to the  72  * bounds of its RelativeLayout parent.  73 */  74 public static final int CENTER_VERTICAL = 15;  75 /**  76  * Rule that aligns a child's end edge with another child's start edge.  77 */  78 public static final int START_OF = 16;  79 /**  80  * Rule that aligns a child's start edge with another child's end edge.  81 */  82 public static final int END_OF = 17;  83 /**  84  * Rule that aligns a child's start edge with another child's start edge.  85 */  86 public static final int ALIGN_START = 18;  87 /**  88  * Rule that aligns a child's end edge with another child's end edge.  89 */  90 public static final int ALIGN_END = 19;  91 /**  92  * Rule that aligns the child's start edge with its RelativeLayout  93  * parent's start edge.  94 */  95 public static final int ALIGN_PARENT_START = 20;  96 /**  97  * Rule that aligns the child's end edge with its RelativeLayout  98  * parent's end edge.  99 */ 100 public static final int ALIGN_PARENT_END = 21;

 

转载于:https://www.cnblogs.com/sjjg/p/5807746.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/160844.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • GIT、GITLAB、GITHUB、GITLIB[通俗易懂]

    GIT、GITLAB、GITHUB、GITLIB[通俗易懂]Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Github-一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等作为开源代码库以及版本控制系统,Github目前拥有140多万开发者用户。随着越来越多的应用程序转移到了云上

  • ftp常用命令详解_ospf生成路由表的过程

    ftp常用命令详解_ospf生成路由表的过程在window下按window+r可打开DOS命令窗口,然后就可以输入FTP命令了。1.登录FTP服务器方法一:直接输入ftp加ip地址ftp192.168.10.xxx方法二:直接输入ftp,进入ftp服务后输入open加ip地址open192.168.10.xxx当连接成功后会让你进行身份验证,在输入密码时屏幕上没有任何显示,不用管,直接…

  • Oracle经验总结!

    Oracle经验总结!

  • MySQL重设密码_mysql重置密码命令

    MySQL重设密码_mysql重置密码命令1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和修改MySQL的信息。可以采用将MySQL对外的端口封闭,并且停止Apache以及所有的用户进程的方法实现服务器的准安全状态。最安全的状态是到服务器的Console上面操作,并且拔掉网线。2.修改MyS…

    2022年10月16日
  • 整除计算器_0 整除

    整除计算器_0 整除原题链接这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1、11、111、1111等。传说任何一个光棍都能被一个不以5结尾的奇数整除。比如,111111就可以被13整除。 现在,你的程序要读入一个整数x,这个整数一定是奇数并且不以5结尾。然后,经过计算,输出两个数字:第一个数字s,表示x乘以s是一个光棍,第二个数字n是这个光棍的位数。这样的解当然不是唯一的,题目要求你输出最小的解。提示:一个显然的办法是逐渐增加光棍的位数,直到可以整除x为止。但难点在于,s可能是个非常大的数 ——

  • dede中弹出框函数function ShowMsg

    dede中弹出框函数function ShowMsg

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号