android - ScrollView 在 ListView 中不起作用

标签 android scrollview

我在此布局中有多个线性布局。当我完全滚动该项目时, ScrollView 正在工作,但在 ListView 中不起作用。我的 ListView 有多个列表项,它一次只显示一个列表项,谢谢帮助我......

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:scrollbars="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/txtdate"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector" />

            <Button
                android:id="@+id/btnTaskTimeid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/txtItem"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/edittextselector"
                android:drawableEnd="@drawable/inbox"
                android:gravity="top|left"
                android:hint="Enter task"
                android:inputType="textMultiLine"
                android:maxLines="5"
                android:minLines="3"
                android:scrollbars="vertical"
                android:singleLine="false" />

            <ImageButton
                android:id="@+id/imagebuttonid"
                android:layout_width="31dp"
                android:layout_height="36dp"
                android:layout_gravity="right|bottom"
                android:background="@drawable/inbox" />
        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/btnaddcategoryid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="AddCategory" />

            <Button
                android:id="@+id/btnaddseverityid"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="AddSeverity" />
        </LinearLayout>

        <Button
            android:id="@+id/btnadddb"
            android:layout_width="wrap_content"
            android:layout_height="30px"
            android:layout_gravity="center|center_horizontal"
            android:layout_marginTop="10dp"
            android:background="@drawable/taskbuttonselector"
            android:text="Add This Task" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:weightSum="2" >

            <Button
                android:id="@+id/fillbut"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="Remain Task" />

            <Button
                android:id="@+id/remainbut"
                android:layout_width="0dip"
                android:layout_height="30px"
                android:layout_weight="1"
                android:background="@drawable/taskbuttonselector"
                android:text="Finish Task" />
        </LinearLayout>

        <ListView
            android:id="@+id/listid"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:clickable="true"
            android:orientation="vertical" >
        </ListView>
    </LinearLayout>

</ScrollView>

最佳答案

切勿将 ListView 放入 ScrollView 中,反之亦然! documentation 中就是这么说的。 :

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

关于android - ScrollView 在 ListView 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449391/

相关文章:

java - achartengine饼图未在 ScrollView 中呈现

android - 在 ScrollView Android 中处理触摸事件

android: scrollView 中的 ListView 不起作用?

ios - 无法滚动ScrollView

Android去除videoview弹出信息

android - 如何使用 onPause(后退按钮)发送结果 Intent

android - 我如何获得 webView(android) 的当前比例

android - ScrollView Scrollbartrack 可见性

android - 针对不同 API 级别的多个 APK 或单个 APK?

java - 使用 TCP 在 Java(Android 客户端)和 C(PC 服务器 - Linux)之间传输文件