【发布时间】:2020-06-12 08:35:01
【问题描述】:
我正在尝试使用ConstraintLayout 作为parent 进行布局,其中包含三个buttons,如下图所示。
xml 布局文件如下所示:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Button
android:id="@+id/splash_facebook_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="15dp"/>
<Button
android:id="@+id/splash_sign_in_btn"
android:layout_width="180dp"
android:layout_height="45dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/splash_facebook_btn" />
<Button
android:id="@+id/splash_sign_up_btn"
android:layout_width="180dp"
android:layout_height="45dp"
android:layout_marginEnd="15dp"
app:layout_constraintBottom_toBottomOf="@id/splash_sign_in_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.995"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@id/splash_sign_in_btn"
app:layout_constraintTop_toTopOf="@id/splash_sign_in_btn"
app:layout_constraintVertical_bias="0.0" />
我想这样做而不为底部的两个按钮设置固定值。
我知道我可以通过更改为 LinearLayout 并使用 layout_weight 来实现这一点,但我想在拥有 ConstraintLayout 作为父级的同时做到这一点。
有没有办法做到这一点?
【问题讨论】:
标签: android xml user-interface layout android-constraintlayout