android - layout_height ="match_parent"不按预期工作

标签 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"
    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 的高度和宽度都明确设置为匹配其父级,它也匹配 CardView 的宽度但在高度方向包裹其内容。 为什么会这样?

最佳答案

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

关于android - layout_height ="match_parent"不按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57838536/

相关文章:

xml - 编辑xml文件shell脚本

javascript - jquery ajax 调用强制响应中的 XML 元素名称为小写

xml - 添加超链接到 indesign

android - 清除 fragment 中的操作栏

java - 无法解析符号

java - 不幸的是该应用程序已停止

Android链接地址而不显示完整地址

java - Java 中的 ".class"关键字

Python 元素树 : Ignore undefined prefixes

python - 如何使用 wsdl2py 生成的复杂类型从 python 中的 Web 服务发送响应