我正在创建一个自定义对话框。我有2个按钮,“选择其他卡”和“确定”,但不知何故“确定”按钮不会显示。我是使用LineairLayouts的新手。我有一个垂直的水平布局。
对话框显示的内容:
我希望对话框显示的内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical"
android:padding="5dp"
android:background="@color/colorLightBlue"
android:onClick="selectOtherCardsButtonClick">
<TextView
android:id="@+id/finishedTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:fontFamily="@font/patrickhand_regular"
android:text="@string/finishedCards"
android:textColor="@color/colorWhite"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/selectOtherButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="@+id/selectOtherButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/button_background"
android:text="@string/selectOtherCards"
android:textColor="@color/colorWhite"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/button_background"
android:text="@string/ok"
android:textColor="@color/colorWhite"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/selectOtherButton"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</LinearLayout>
我希望任何人都知道我的问题是什么。
谢谢你的帮忙!
可能selectOtherButton
覆盖了所有水平空间,并且在okButton
下方selectOtherButton
。
使用android:layout_weight
两个按钮的属性,定义将覆盖每个按钮的空间的权重,例如4到1(或调整它以适合您的设计):
<Button
android:id="@+id/selectOtherButton"
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/button_background"
android:text="@string/selectOtherCards"
android:textColor="@color/colorWhite"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/okButton"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/button_background"
android:text="@string/ok"
android:textColor="@color/colorWhite"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/selectOtherButton"
app:layout_constraintTop_toTopOf="parent" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句