【问题标题】:NestedScrollview inside a Recycler view not scrollingRecycler 视图中的 NestedScrollview 不滚动
【发布时间】:2016-09-28 06:13:37
【问题描述】:

我正在创建一个 Android 程序。在这个程序中,我有一个 ScrollView,里面有一个 RecyclerView。我通过 RecyclerViewAdapter 在这个 RecyclerView 中添加数据。

对于 RecyclerView 的每个项目,都有一个 NestedScrollview,它具有一个垂直方向的 LinearLayout。我在此 LinearLayout 中动态添加 ImageView。

问题是图像没有滚动。在非常罕见的情况下(通过在屏幕上点击这么多次),它会滚动一次。

有人可以帮我解决这个问题吗?

这里是代码-

父回收者视图:-

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
    <android.support.v7.widget.RecyclerView
        android:id="@+id/id_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@color/gray3"
        android:dividerHeight="5sp"
        android:paddingLeft="2sp"
        android:paddingTop="5sp"
        android:paddingRight="2sp"/>
        <com.app.sh.widget.WrappedGridView
            android:id="@+id/gridView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/White"
            android:numColumns="2">

        </com.app.socialhand.widget.WrappedGridView>

    </LinearLayout>
</ScrollView>

以及回收站视图的项目:-

<android.support.v4.widget.NestedScrollView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/vScrollView"
              android:layout_below="@id/iv_up"
              android:layout_above="@+id/iv_down"
              android:isScrollContainer="true"
              >
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
              <LinearLayout
                  android:id="@+id/ll_123"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  >

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

我在 ll_123 中动态添加 ImageView。

【问题讨论】:

    标签: android android-recyclerview


    【解决方案1】:

    尝试使用 NestedScrollView 而不是 ScrollView 或将其删除。 RecyclerView 有自己的滚动视图,会和 ScrollView 冲突。

    【讨论】:

    • 我也尝试过使用 Nested ScrollView,但它仍然无法正常工作。如果没有任何滚动视图,回收站视图根本不会滚动。
    【解决方案2】:

    你可以试试这样的结构:

    <ScrollView>
        <NestedScrollView>
            <LinearLayout>
                <RecyclerView/>
            </LinearLayout>
        </NestedScrollView>
    </ScrollView>
    

    ListItem 布局应该包含:

    <NestedScrollView>
        <LinearLayout/>
    </NestedScrollView>
    

    检查这是否正常工作...

    【讨论】:

    • 感谢 chintan 的回复。但这个逻辑对我不起作用。
    【解决方案3】:

    我遇到了类似的问题,这对我有帮助:

    <ScrollView
        android:id="@+id/messages_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/send_panel"
        android:fillViewport="true"
        android:padding="5dp">
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:id="@+id/messages"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="5dp"
                android:animateLayoutChanges="true"
                android:gravity="center_horizontal|bottom"
                android:orientation="vertical">
    
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>
    

    【讨论】:

    • 我已根据您的代码更改了回收站的项目布局,但它不起作用。在将回收站的项目设为 ScrollView 而不是 NestedScrollView 时,父列表开始滚动,同时尝试滚动子列表。
    【解决方案4】:
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <-only one layout in nestade layout-> 
    
        <LinearLayout
            android:id="@+id/activity_edit_existing_location"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/rcl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
            <-put here yr second layout code->
    
    
            </RelativeLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

    • 没有得到您的建议代码 madhav。能否详细说明一下。
    猜你喜欢
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多