【问题标题】:Why isn't my whole LineairLayout showing?为什么我的整个 LinearLayout 没有显示?
【发布时间】:2021-04-12 15:18:48
【问题描述】:

我正在制作一个自定义对话框。我有 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>

我希望有人知道我的问题是什么。

感谢您的帮助!

【问题讨论】:

    标签: android xml dialog android-linearlayout


    【解决方案1】:

    可能selectOtherButton 覆盖了所有水平空间,okButtonselectOtherButton 之下。

    为将覆盖每个按钮的空间定义权重,例如 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" />
    

    【讨论】:

      【解决方案2】:

      尝试减小文本大小,例如尝试:

      android:textSize="14sp"

      或少用一些词,例如:select others。权重可能会将按钮转换为两行。最后可能看起来不太好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-05-12
        • 2013-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多