【问题标题】:ListView not scrolling inside of NestedScrollViewListView 不在 NestedScrollView 内滚动
【发布时间】:2016-04-13 08:49:55
【问题描述】:

我在 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"

感谢您的帮助!

【问题讨论】:

  • 使用recyclerview,listview不能使用nestedscrolling功能。
  • @oguzhand 有什么办法可以让它与 listView 一起工作吗?
  • 因为滚动在 ListView 中可用,所以不能使用 ScrollView 包装它。所以改为将 layout_height 设置为一些 dp 说它 200dp,然后布局将滚动。如果您在该布局中仅使用 ListView,则不必将 NestedScrollView 包装起来。
  • RecyclerView 和 NestedScrollView 是为协同工作而设计的,ListView 是一个旧的小部件,不支持嵌套滚动。您可以管理它,但您的回收结构将不起作用(这是不合逻辑的)。我几个月都没有使用 Listview。只需使用 RecyclerView。
  • 好的,我将切换到 RecyclerView,谢谢!你真的帮了我。 @oguzhand

标签: android listview nestedscrollview


【解决方案1】:

使用ViewCompat.setNestedScrollingEnabled() 应该没问题。

【讨论】:

    【解决方案2】:

    这是因为在滚动视图(NestedScrollView)中使用了 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"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多