首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓: ConstraintLayout布局4个按钮,分成2组,分布不均

安卓: ConstraintLayout布局4个按钮,分成2组,分布不均
EN

Stack Overflow用户
提问于 2017-07-24 23:29:24
回答 2查看 130关注 0票数 0

如何在ConstraintLayout上将4个按钮分成2组来实现类似于下图的效果?

这两组按钮必须通过一些额外的填充适当地左/右对齐。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-24 23:40:44

只需将最左边和最右边的按钮约束到父级的边缘,并将内部按钮约束在外部按钮上。

代码语言:javascript
运行
复制
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#eee">

    <Button
        android:id="@+id/l1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="L1"
        app:layout_constraintLeft_toLeftOf="parent"/>

    <Button
        android:id="@+id/l2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="L2"
        app:layout_constraintLeft_toRightOf="@+id/l1"/>

    <Button
        android:id="@+id/r1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="R1"
        app:layout_constraintRight_toLeftOf="@+id/r2"/>

    <Button
        android:id="@+id/r2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="R2"
        app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>

票数 2
EN

Stack Overflow用户

发布于 2017-07-25 00:33:41

使用widget在约束布局中分隔两组按钮。GuideLine是基于百分比的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45284542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档