RelativeLayout.LayoutParams
通过id设置相对兄弟元素对齐。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/lyla_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="24sp"
android:text="Lyla" /> <TextView
android:id="@+id/me_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/lyla_text_view"
android:textSize="24sp"
android:text="Me" /> <TextView
android:id="@+id/natalie_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/lyla_text_view"
android:textSize="24sp"
android:text="Natalie" /> <TextView
android:id="@+id/jennie_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="24sp"
android:text="Jennie" /> <TextView
android:id="@+id/omoju_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/jennie_text_view"
android:textSize="24sp"
android:text="Omoju" /> <TextView
android:id="@+id/amy_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_above="@id/omoju_text_view"
android:layout_alignParentRight="true"
android:textSize="24sp"
android:text="Amy" /> <TextView
android:id="@+id/ben_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:text="Ben" /> <TextView
android:id="@+id/kunal_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kunal" /> <TextView
android:id="@+id/kagure_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kagure" /> </RelativeLayout>
相对兄弟节点(id)放置
XML属性 |
|
|---|---|
android:layout_above |
将此视图的下边缘定位在给定锚点视图ID上方。 |
android:layout_alignBaseline |
将此视图的基线定位在给定锚点视图ID的基线上。 |
android:layout_alignBottom |
使此视图的下边缘与给定锚点视图ID的下边缘匹配。 |
android:layout_alignEnd |
使此视图的结束边缘与给定锚点视图ID的结束边缘匹配。 |
android:layout_alignLeft |
使此视图的左边缘与给定锚点视图ID的左边缘匹配。 |
android:layout_alignParentBottom |
如果为true,则使此视图的下边缘与父级的下边缘匹配。 |
android:layout_alignParentEnd |
如果为true,则使此视图的结束边缘与父级的结束边缘匹配。 |
android:layout_alignParentLeft |
如果为true,则使此视图的左边缘与父窗口的左边缘匹配。 |
android:layout_alignParentRight |
如果为true,则使此视图的右边缘与父级的右边缘匹配。 |
android:layout_alignParentStart |
如果为true,则使此视图的起始边缘与父级的起始边缘匹配。 |
android:layout_alignParentTop |
如果为true,则使此视图的上边缘与父级的上边缘匹配。 |
android:layout_alignRight |
使此视图的右边缘与给定锚点视图ID的右边缘匹配。 |
android:layout_alignStart |
使此视图的起始边缘与给定锚点视图ID的起始边缘匹配。 |
android:layout_alignTop |
使此视图的上边缘与给定锚点视图ID的上边缘匹配。 |
android:layout_alignWithParentIfMissing |
如果设置为true,则在无法找到layout_toLeftOf,layout_toRightOf等的锚点时,父项将用作锚点。 |
android:layout_below |
将此视图的上边缘定位在给定锚点视图ID下方。 |
android:layout_centerHorizontal |
如果为true,则将此子项水平居中于其父级。 |
android:layout_centerInParent |
如果为true,则将此子项在其父级中水平和垂直居中。 |
android:layout_centerVertical |
如果为true,则将此子项垂直居中于其父项中。 |
android:layout_toEndOf |
将此视图的起始边缘定位到给定锚点视图ID的末尾。 |
android:layout_toLeftOf |
将此视图的右边缘定位在给定锚点视图ID的左侧。 |
android:layout_toRightOf |
将此视图的左边缘定位到给定锚点视图ID的右侧。 |
android:layout_toStartOf |
将此视图的结束边缘定位到给定锚点视图ID的开头。 |
RelativeLayout.LayoutParams的更多相关文章
- RelativeLayout.LayoutParams.addRule()方法
1.应用场景 在使用RelativeLayout布局的时候,通常在载入布局之前在相关的XML文件中进行静态设置即可.但是,在有些情况下,我们需要动态的设置布局 的属性,在不同条件下设置不同的布局排列方 ...
- Android 动态改变布局属性RelativeLayout.LayoutParams.addRule()
我们知道,在 RelativeLayout 布局中有很多特殊的属性,通常在载入布局之前,在相关的xml文件中进行静态设置即可. 但是,在有些情况下,我们需要动态设置布局的属性,在不同的条件下设置不同的 ...
- 代码中动态改变布局属性RelativeLayout.LayoutParams.addRule()
我们知道,在 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 ...
- java.lang.ClassCastException android.widget.RelativeLayout LayoutParams 异常
1.在xml布局文件如下所示: <RelativeLayout android:layout_width="match_parent" android:layout_heig ...
- 用代码设置 RelativeLayout.LayoutParams
1.注意 不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为 ALIGN_ ...
- Exception: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
RelativeLayout title_bg = (RelativeLayout)FTU_Bluetooth.this.findViewById(R.id.titlebar); LinearLayo ...
- 为什么relativelayout.layoutParams的width为-1
源码里看下就知道了.. -1不代表宽度,代表MATCH_PARENT常量的值public static final int FILL_PARENT = -1; public static final ...
- java写RelativeLayout 的属性
有时项目需要动态的调整一下布局,需要改变一些view的位置属性等等. 直接下代码 RelativeLayout.LayoutParams params=new RelativeLayout.Layou ...
随机推荐
- php.ini 中文版
作者:金步国 版权声明 本文作者是一位开源理念的坚定支持者,所以本文虽然不是软件,但是遵照开源的精神发布. 无担保:本文作者不保证作品内容准确无误,亦不承担任何由于使用此文档所导致的损失. 自由使用: ...
- xfsdump命令使用
一:使用xfsdump备份和恢复xfs文件系统 首先了解一下xfsdump的备份级别有以下两种,默认为0(即完全备份) 0 完全备 ...
- 【MyBatis】MyBatis之分页
关于MyBatis的搭建可以参见“MyBatis的配置”,MyBatis是对JDBC底层代码的封装,关于Oracle.MySQL.SqlServer的分页可以查看Oracle.SqlServer.My ...
- formValidator输入验证、异步验证实例 + licenseImage验证码插件实例应用
实例技术:springmvc 实现功能:完整用户登录流程.输入信息规则校验.验证码异步校验. 功能清单: 1.springmvc控制器处理get请求(/member/login.html),进行静态页 ...
- Eclipse中Ant的配置与测试
在Eclipse中使用Ant Ant是Java平台下非常棒的批处理命令执行程序,能非常方便地自动完成编译,测试,打包,部署等等一系列任务,大大提高开发效率.如果你现在还没有开始使用Ant,那就要赶快开 ...
- Java 8 – Stream Collectors groupingBy count examples
Java 8 – Stream Collectors groupingBy count examples 1. Group By, Count and Sort1.1 Group by a List ...
- HBase中多Filter查询示例
在Hbase查询中有时需要用到多个Filter关联的查询. 代码如下: ArrayList<Filter> listForFilters = new ArrayList<Filter ...
- Apache Hadoop下一代MapReduce框架(YARN)简介 (Apache Hadoop NextGen MapReduce (YARN))
英文看着头大,先试着翻译一下. E文原文:http://archive.cloudera.com/cdh5/cdh/5/hadoop/hadoop-yarn/hadoop-yarn-site/YARN ...
- 将多个 docx 文件使用 POI 进行合并,生成单个文档,包含图片
1 添加 maven 依赖,需要使用 poi 的依赖项 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad ...
- 关于haproxy多域名证书的配置
frontend main bind *: bind *: ssl crt /etc/haproxy/kong.com.pem crt /etc/haproxy/51yijI.com.pem no-s ...