[英]You must supply a layout_height attribute error in android listview
[英]Error in Listview android:layout_height
最近,我开始学习有关Android App开发的知识。 今天,我试图建立一个ListView。 但是在Listview属性中,我在android:layout_height中遇到了错误。 我将“ layout_height”设置为“ match_parent”,“ wrap_content”和“ fill_parent”。 但是在这种情况下,每种情况下都有一条红线。
<?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>
将列表视图更改为以下内容:
<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/
1.只是去Build-> Rebuild project 2.Build-> clean project希望它能工作:)
转到文件->'使缓存无效/重新启动',然后重新启动Studio。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.