循环器视图内的NestedScrollview不滚动

时间:2016-09-28 06:13:37

标签: android android-recyclerview

我正在创建一个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中动态添加ImageViews。

4 个答案:

答案 0 :(得分:0)

尝试使用NestedScrollView而不是ScrollView或删除它。 RecyclerView有自己的scrollview,它将与ScrollView冲突。

答案 1 :(得分:0)

您可以尝试以下结构:

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

ListItem布局应包含:

<NestedScrollView>
    <LinearLayout/>
</NestedScrollView>

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

答案 2 :(得分:0)

我遇到了同样的问题,这对我有所帮助:

<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>

答案 3 :(得分:0)

<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>
相关问题