我对约束布局概念很陌生。我想创建一个连续 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>
Run Code Online (Sandbox Code Playgroud)
我在下面添加了屏幕截图: