列表视图中的错误 android:layout_height

Error in Listview android:layout_height

最近我开始学习 Android 应用程序开发。今天我正在尝试构建一个 ListView。但是在 Listview 属性中,我在 android:layout_height 中遇到了错误。我将我的 layout_height 设置为 "match_parent"、"wrap_content" 和 "fill_parent"。但在每种情况下,this 下都有一条红线。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.sourav.myapplication.MainActivity">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

转到文件 -> 'Invalidate Caches/Restart' 并重新启动工作室。

将您的列表视图更改为以下内容:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
</LinearLayout>

我在 http://jamesbyars.github.io/android/Android-ListView-Height/

与自己抗争后写了一篇简短的博客 post

1.Just 转到构建-->重建项目 2. 构建 --> 清理项目 希望它会起作用:)