【发布时间】:2018-09-10 18:06:18
【问题描述】:
我是约束布局概念的新手。我想创建一个连续 3 个视图的布局。 2 视图应显示没有任何重量,第 3 视图应占据屏幕的第二半。基本上我想将下面的代码转换为约束布局。 此外,当第三个视图可见性消失时,剩余的两个视图应该占据所有宽度。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:layout_weight="1">
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="he" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="he" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:layout_weight="1">
<Button
android:id="@+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello2" />
</LinearLayout>
</LinearLayout>
我在下面添加了截图:
【问题讨论】:
标签: android android-constraintlayout