簡體   English   中英

Listview android:layout_height中的錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM