2016-09-28 77 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。你能否詳細說明一下。 –

相關問題