Ограничение Макет скрыть вид с весом цепи

Hy,

Я хочу, чтобы 2 вида одинаково распределяли ширину экрана в ConstraintLayout. Для этого использовались цепи и вес.

<Button
    android:id="@+id/buttonLeft"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="0dp"
    android:text="Left"
    app:layout_constraintHorizontal_chainStyle="spread_inside"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toLeftOf="@+id/guidelineLeft"
    app:layout_constraintRight_toLeftOf="@+id/buttonRight"
    tools:layout_editor_absoluteY="0dp"/>

<Button
    android:id="@+id/buttonRight"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_marginRight="0dp"
    android:text="Right"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toRightOf="@+id/buttonLeft"
    app:layout_constraintRight_toLeftOf="@+id/guidelineRight"
    tools:layout_editor_absoluteY="0dp"/>

Теперь я хочу скрыть правый вид, а левый увеличить, чтобы заполнить ширину.

Я думал, что это может работать из коробки из-за поведения видимости

Но поскольку левая кнопка имеет ограничение на правую, она не растет.

Любые идеи, как это решить?


person cwiesner    schedule 23.02.2017    source источник


Ответы (1)


Скрытие правого вида работает:

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

    <Button
        android:id="@+id/buttonLeft"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:text="Left"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineLeft"
        app:layout_constraintRight_toLeftOf="@+id/buttonRight"
        tools:layout_editor_absoluteY="0dp"/>

    <Button
        android:id="@+id/buttonRight"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_marginRight="0dp"
        android:text="Right"
        android:visibility="gone"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf="@+id/buttonLeft"
        app:layout_constraintRight_toLeftOf="@+id/guidelineRight"
        tools:layout_editor_absoluteY="0dp"/>

    <android.support.constraint.Guideline
        android:id="@+id/guidelineLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_begin="20dp"
        android:orientation="vertical" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guidelineRight"
        android:orientation="vertical"
        app:layout_constraintGuide_end="70dp" />

</android.support.constraint.ConstraintLayout>

... но скрытие левого вида не работает. Я сообщил об ошибке здесь: https://code.google.com/p/android/issues/detail?id=234897

person Nicolas Roard    schedule 23.02.2017
comment
Спасибо за быстрый ответ. но если я использую предложенный вами макет, левый вид не увеличивается, когда правый скрыт. по крайней мере редактор компоновки его не показывает. см. здесь - person cwiesner; 24.02.2017