前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RelativeLayout.LayoutParams

RelativeLayout.LayoutParams

作者头像
全栈程序员站长
发布2022-09-07 11:32:59
4350
发布2022-09-07 11:32:59
举报
文章被收录于专栏:全栈程序员必看

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

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

<span role="heading" aria-level="2">RelativeLayout.LayoutParams
<span role="heading" aria-level="2">RelativeLayout.LayoutParams
<span role="heading" aria-level="2">RelativeLayout.LayoutParams
<span role="heading" aria-level="2">RelativeLayout.LayoutParams
<span role="heading" aria-level="2">RelativeLayout.LayoutParams
<span role="heading" aria-level="2">RelativeLayout.LayoutParams
代码语言:javascript
复制
<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的开头。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/154769.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档