微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我的整个 LineairLayout 不显示?

如何解决为什么我的整个 LineairLayout 不显示?

我正在制作自定义对话框。我有 2 个按钮,“选择其他卡”和“确定”,但不知何故“确定”按钮不会显示。我是使用 LineairLayouts 的新手。我在垂直布局中有一个水平布局。

对话框显示内容

enter image description here

我希望对话框显示什么:

enter image description here

<?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 之下。

为将覆盖每个按钮的空间定义权重,例如 4 比 1(或调整它以适合您的设计),并为两个按钮使用 android:layout_weight 属性:

   <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" />
,

尝试降低文本大小,例如:

android:textSize="14sp"

或使用更少的词,例如:select others。重量可能会将按钮转换为两行。而且它最终可能看起来不太好。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。