约束布局隐藏带链重的视图(Constraint Layout hide View with chain weight)

编程入门 行业动态 更新时间:2024-10-25 03:27:35
约束布局隐藏带链重的视图(Constraint Layout hide View with chain weight)

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"/>

现在我想隐藏正确的视图和左边增长以填充宽度。

我认为由于可见性行为,这可以开箱即用

但由于左按钮在右边有一个约束,它不会增长。

任何想法如何解决?

Hy,

I want to have 2 Views equally spread the screen width in a ConstraintLayout. Used chains and weight to achieve that.

<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"/>

Now i want to hide the right View and the left to grow to fill the width.

I thought this could work out of the box because of the visiblity behaviour

But as the left button has a constraint on the right one, it does not grow.

Any ideas how to solve that?

最满意答案

隐藏正确的视图有效:

<?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

Hiding the right view works:

<?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>

... but hiding the left view doesn't. I filed a bug here: https://code.google.com/p/android/issues/detail?id=234897

更多推荐

本文发布于:2023-08-07 23:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466433.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   布局   Constraint   Layout   带链重

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!