android - LinearLayout 未正确居中
问题描述
大家下午好。
我有两个 LinearLayouts 一个在另一个之下。两者都包括两个居中的按钮。
我需要顶部布局和底部布局上的按钮之间的空白区域匹配而不更改宽度按钮。
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_contenedorContador">
<LinearLayout
android:id="@+id/layout_botonRespuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_textoPregunta">
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quiz_falso" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quiz_verdadero" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_botonNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_botonRespuesta">
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quiz_atras" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quiz_siguiente" />
</LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>
更新
在这里,我展示了一张图像,表明我想要如何分配。红线仅作引导
解决方案
改变
android:weightSum="2" 的线性布局和按钮宽度为 android:layout_width="0dp" 并添加布局权重线 android:layout_weight="1"。
<LinearLayout
android:id="@+id/layout_botonRespuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_textoPregunta">
<Button
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="falso" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="verdadero" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_botonNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_botonRespuesta">
<Button
android:id="@+id/button10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="atras" />
<Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="siguiente" />
</LinearLayout>
推荐阅读
- javascript - 如何监视组件中的 vuex 突变/动作?
- android - 错误:无法使用 viewpager2 中 FragmentStateAdapter 中提供的参数调用以下函数
- javascript - 在 onClick 操作后,React 的动态表不会重新渲染
- angular - Angular 9 反应形式:动态添加的验证器不显示错误消息
- entity-framework-core - 无法在 .NET Framework4.8 项目中使用 EF Core3.1
- ansible - Ansible 无法使用查找将变量传递给角色?
- java - 使用画布旋转在Android中性能不佳的图形
- javascript - 使用原生 javascript/sealCrypto 使用 RSA 进行加密
- android - 用户未注册(Flutter Firebase)
- javascript - 列表中的多个过滤器