【问题标题】:Android ListView wraps inside a parent while shouldn'tAndroid ListView 包含在父级中,而不应包含在父级中
【发布时间】:2017-01-12 17:26:34
【问题描述】:

我正在开发一个安卓应用。 我的主要活动中有多个导航抽屉。它们的定义如下:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/drawer_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"/>
<ListView android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="fill_parent"
    android:layout_gravity="left"
    android:choiceMode="singleChoice"
    android:divider="@android:color/black"
    android:dividerHeight="5dp"
    android:background="#e1fcff"
    />
<ListView android:id="@+id/right_drawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="end"
    android:choiceMode="singleChoice"
    android:divider="@android:color/black"
    android:dividerHeight="5dp"
    android:background="#e1fcff"
    android:layout_marginLeft="-64dp"
    />

<ListView android:id="@+id/contacts_drawer_right"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="end"
    android:choiceMode="singleChoice"
    android:divider="#ffff2a00"
    android:dividerHeight="5dp"
    android:background="#e1fcff"
    android:layout_marginLeft="-64dp"
    />

我在“contacts_drawer_right listview”中填充了一个RelativeLayout,它的内部也有一个listView(id=contactsListView)。

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical"><ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/contactsListView"
            />
    </ScrollView>
    </RelativeLayout>

我的问题是,contactsListView 没有填充它的父高度,尽管我在它的定义布局文件中使用了android:layout_height="fill_parent"。 我的期望如下: enter image description here 但实际情况如下:enter image description here 而且我也不能滚动列表视图。

请给我一些想法并告诉我如何显示我的列表视图的所有内容(带有填充的父项)。

【问题讨论】:

    标签: android listview scroll


    【解决方案1】:

    尝试这样做,将 scrollView 设为父级:

    <?xml version="1.0" encoding="utf-8"?>
    
       <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
            <RelativeLayout 
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent">
                  <ListView
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:id="@+id/contactsListView"
                    />
             </RelativeLayout>
    </ScrollView>
    

    【讨论】:

    • 如果你只想要一个列表视图,你可以删除 scrollView .... listView 已经是可滚动的,为什么要添加一个 scrollView ??
    猜你喜欢
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 2011-12-21
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    相关资源
    最近更新 更多