ListView在NestedScrollView中无法滚动

3
我是一名有用的助手,可以为您翻译文本。
我在NestedScrollView中使用了ListView。列表已经扩展到与父级匹配,但现在没有滚动条。
下面是我的布局:
<android.support.v4.widget.NestedScrollView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true"
>
       <LinearLayout
           android:orientation="vertical"
           android:layout_width="match_parent"
           android:layout_height="wrap_content">

            <ListView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:id="@+id/workExperienceListLV"
                android:divider="@null"
                android:listSelector="@android:color/transparent"
                android:dividerHeight="0dp"/>

        </LinearLayout>

</android.support.v4.widget.NestedScrollView>

这一行并没有帮助:

android:fillViewport="true"

感谢您的帮助!

1
使用RecyclerView,您不能在ListView中使用嵌套滚动功能。 - Oğuzhan Döngül
@oguzhand 有没有办法让它与listView一起工作? - Elie Daher
由于ListView中已经有滚动条,因此您不能使用ScrollView将其包装。因此,将layout_height设置为一些dp,比如200dp,然后布局将会滚动。如果您在该布局中仅使用ListView,则无需将NestedScrollView包装在其中。 - ABI
RecyclerView和NestedScrollView是为了配合使用而设计的,ListView是一个旧的小部件,不支持嵌套滚动。你可以管理它,但你的回收结构将无法工作(这是不合逻辑的)。我已经好几个月没有使用Listview了。只需使用RecyclerView即可。 - Oğuzhan Döngül
好的,我会切换到RecyclerView,谢谢!你真的帮了我。@oguzhand - Elie Daher
2个回答

0
使用ViewCompat.setNestedScrollingEnabled(),你应该没问题了。

-3

这是因为在ScrollView(NestedScrollView)中使用了ListView。由于两者都具有滚动功能,如果您想要滚动此内容,只需将ListView的宽度减少到屏幕的一半即可。

 <ListView
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:id="@+id/workExperienceListLV"
                android:divider="@null"
                android:listSelector="@android:color/transparent"
                android:dividerHeight="0dp"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接