Android 布局“U高度=”;匹配“家长”;don';我不能如愿工作

Android 布局“U高度=”;匹配“家长”;don';我不能如愿工作,android,xml,Android,Xml,我有一个简单的看法如下 <?xml version="1.0" encoding="utf-8"?> <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" androi

我有一个简单的看法如下

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="60dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_dark"
        android:gravity="center">

        <TextView
            android:Text="Some text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</androidx.cardview.widget.CardView>

尽管
LinearLayout
的高度和宽度都已明确设置为与其父级匹配,但它与
cardwiew
的宽度匹配,但将其内容按高度包装。 为什么会发生这种情况?

我想发表评论,但无论如何,我没有“足够的声誉”。 是否已在gradle文件中添加依赖项“androidx.cardview:cardview:1.0.0”?您的代码对我来说很好,但是,我不知道您是否添加了依赖项。

android:layout_height="match_parent"
cardwiew
LinearLayout
中,表示
LinearLayout
的高度与
cardwiew
的父级高度相同,小于60dp。然后设置

android:minHeight="60dp"
cardwiew
中将其高度更改为60dp,同时保持
线性布局的高度不变。我将
cardwiew
中的这两行替换为

android:layout_height="60dp"
问题解决了


我仍然认为这是不直观的,但看起来情况就是这样。

我没有依赖项,但添加时没有任何更改。