ConstraintLayout问题与水平权重

M-W*_*eEh 6 android android-layout android-constraintlayout

考虑遵循xml布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/b1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="B1"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/b2"/>

    <Button
        android:id="@+id/b2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B2"
        app:layout_constraintLeft_toRightOf="@+id/b1"
        app:layout_constraintRight_toLeftOf="@id/b3"/>

    <Button
        android:id="@+id/b3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B3"
        app:layout_constraintLeft_toRightOf="@+id/b2"
        app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这产生了我想要的布局:

在此输入图像描述

但如果我将B3标记为已消失,则B1的宽度设置为0,B2移至左侧.我希望B2拿B3的位置和B1扩展:

在此输入图像描述

知道我可能做错了什么吗?

Pra*_*olu 5

设置android:layout_width = "0dp"app:layout_constraintHorizontal_weight="1"B2,你准备去.

编辑:只需app:layout_constraintRight_toLeftOf="@id/b3"从B2中删除.