2016-09-28 80 views
2

我正在创建一个Android程序。在这个程序中,我有一个ScrollView,里面有一个RecyclerView。我通过RecyclerViewAdapter在这个RecyclerView中添加数据。Recycler视图内的NestedScrollview不滚动

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

我动态添加ImageViews在ll_123。

回答

0

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

+0

我也尝试过嵌套的ScrollView,但它仍然无法正常工作。没有任何滚动视图,回收站视图根本不滚动。 –

+0

你能显示你的代码吗? – giffell

+0

嗨giffell,我已经添加了代码。 –

0

你可以尝试如下的结构:

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

而列表项的布局应包含以下内容:

<NestedScrollView> 
    <LinearLayout/> 
</NestedScrollView> 

检查此工作正确...

+0

非常感谢你的回复。但逻辑不适合我。 –

0

我simmilar问题,这有助于我:

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

我已根据您的代码更改回收商的项目布局,但它不起作用。在将回收站的项目设置为ScrollView而不是NestedScrollView时,父列表在尝试滚动子列表时开始滚动。 –

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

没有得到你的建议代码madhav。你能否详细说明一下。 –

相关问题