Android: Scrollable preferences window with custom list view

自作多情 提交于 2019-12-02 08:48:01

Well, first off, there is really no reason to encapsulate your ListView inside of a Linear Layout inside of a Linear Layout. In fact, there is no reason to encapsulate any of your views inside two LinearLayouts. Try this and see what happens:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/llContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        </ListView>

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAppearance="?android:attr/textAppearanceLarge" >
        </TextView>

        <ListView
            android:id="@+id/lstPlaces"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <EditText
            android:id="@+id/txtNewPlaceName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </EditText>

        <Button
            android:id="@+id/btnAddNewPlace"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add New" >
        </Button>

    </LinearLayout>

</ScrollView>

Never put a ListView inside a ScrollView because there is no good way to differentiate between two nested scrollable containers.

Max Mumford

Similer problem with solution on this thead:

Android ScrollView layout problem

Unfortunatly it looks like you cannot have a listview in a scrolllayout.

For people who are interested, looks like a potential workaround could be found here either now or in the future:

ListView in ScrollView potential workaround

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!