我一直在阅读有关如何让Android在ConstraintLayout中自动设置高度的几个主题。 建议将高度设置为“ 0dp”,但这不适用于我的项目。 我认为问题是在LinearLayout中如何有两个FrameLayout,它们定义了我的搜索杆的比例。
我想要的是:我希望两个搜寻栏填满所有剩余空间,而断开按钮位于屏幕的最底部。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.xxx.zz"
android:orientation="vertical">
<LinearLayout
android:id="@+id/topFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView9"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="@drawable/pic1" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginBottom="7dp"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topFrame">
<TextView
android:id="@+id/batteryStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Battery Level: High"
android:textColor="#FFFFFF"
android:textSize="30dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:weightSum="5"
app:layout_constraintBottom_toTopOf="@+id/linearLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout2">
<FrameLayout
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:text="M1"
android:textColor="@color/colorText" />
</FrameLayout>
<CheckBox
android:layout_marginStart="5dp"
android:id="@+id/reverseM1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Rev"
android:layout_weight="1" />
<CheckBox
android:layout_marginEnd="5dp"
android:id="@+id/reverseM2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Rev"
android:layout_weight="1" />
<FrameLayout
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginEnd="10dp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:text="M2"
android:textColor="@color/colorText" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout5">
<FrameLayout
android:layout_width="100dp"
android:layout_height="450dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout5"
app:layout_constrainedHeight="true"
app:layout_constraintHeight_default="spread"
app:layout_constraintWidth_default="wrap">
<SeekBar
android:id="@+id/slider_1"
android:layout_width="350dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:min="0"
android:max="100"
android:rotation="270"
android:progress="50"
android:progressDrawable="@android:color/transparent"
android:thumb="@drawable/seekbar_thumb" />
</FrameLayout>
<FrameLayout
android:layout_width="100dp"
android:layout_height="450dp"
android:layout_marginStart="150dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout5">
<SeekBar
android:id="@+id/slider_2"
android:layout_width="350dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:min="0"
android:max="100"
android:rotation="270"
android:progress="50"
android:progressDrawable="@android:color/transparent"
android:thumb="@drawable/seekbar_thumb" />
</FrameLayout>
<!--<FrameLayout
android:layout_width="100dp"
android:layout_height="450dp"
android:layout_marginStart="0dp"
android:orientation="vertical">
<CheckBox
android:id="@+id/reverseM1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Reverse M1" />
</FrameLayout>-->
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/btnDisconnect"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Disconnect"
app:backgroundTint="#126FB7" />
</LinearLayout>
<!--<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical"
android:background="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/btnDisconnect"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="10dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:text="Disconnect"
app:backgroundTint="#126FB7" />
</LinearLayout>-->
</androidx.constraintlayout.widget.ConstraintLayout>`