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

GridLayout中Cardview的TextView在小屏幕上消失

如何解决GridLayout中Cardview的TextView在小屏幕上消失

我有以下 mxl 布局文件。在我测试过的大多数屏幕上(其中 dpi 大于 420),我得到了下面第一张图片显示的所需结果。但是当 dpi 下降并且屏幕尺寸缩小时,文本会隐藏(如图 2 和图 3 所示)或显示为已损坏。我该如何解决

<?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:layout_gravity="center_vertical"
android:orientation="vertical"
android:background="@color/white"
android:weightSum="11"
tools:context=".social.bottomnav.ui.dashboard.DashboardFragment">

<GridLayout
    android:id="@+id/dashboardGrid"
    android:rowCount="2"
    android:columnCount="2"
    android:alignmentMode="alignMargins"
    android:layout_gravity="center"
    android:background="@color/white"
    android:columnorderPreserved="false"
    android:layout_weight="11"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:padding="14dp">

    <!-- ROW 1  -->
    <!-- COLUMN 1  -->

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_marginBottom="16dp"
        android:layout_rowWeight="1"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:backgroundTint="#6FDCBD"
        app:cardElevation="1dp"
        app:cardCornerRadius="32dp">

        <LinearLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:src="@drawable/ic_dog_icon"
                android:layout_gravity="center_horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:textAlignment="center"
                android:text="@string/breeds"
                android:textColor="#000"
                android:textSize="22sp"
                android:layout_gravity="center"
                android:textStyle="normal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

    <!-- COLUMN 2  -->

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_marginBottom="16dp"
        android:layout_rowWeight="1"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:backgroundTint="#DC9B6F"
        app:cardElevation="1dp"
        app:cardCornerRadius="32dp">

        <LinearLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:src="@drawable/ic_bowl_icon"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/food"
                android:textAlignment="center"
                android:textColor="#000"
                android:textSize="22sp"
                android:textStyle="normal" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>



    <!-- ROW 2  -->
    <!-- COLUMN 1  -->

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_marginBottom="16dp"
        android:layout_rowWeight="1"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:backgroundTint="#EFE391"
        app:cardElevation="1dp"
        app:cardCornerRadius="32dp">

        <LinearLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:src="@drawable/ic_alarm"
                android:layout_gravity="center_horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:textAlignment="center"
                android:text="@string/alarms"
                android:textColor="#000000"
                android:textSize="22sp"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

    <!-- COLUMN 2  -->




    <!-- ROW 3  -->
    <!-- COLUMN 1  -->



    <!-- COLUMN 2  -->

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_marginBottom="16dp"
        android:layout_rowWeight="1"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:backgroundTint="#55E35C"
        app:cardElevation="1dp"
        app:cardCornerRadius="32dp">

        <LinearLayout
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:src="@drawable/ic_map_icon"
                android:layout_gravity="center_horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:textAlignment="center"
                android:text="@string/nearby"
                android:textColor="#000"
                android:textSize="22sp"
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</GridLayout>

The layout I want

The layout on smaller screens

enter image description here

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