2017-04-19 11 views
0

私は2つの垂直(1行)RecyclerViewsを含む私の活動で複数のビューを持っています。私はsetNestedScrollingEnabled(false)でRecyclerViewsのスクロールを無効にし、アクティビティ全体をスクロール可能にしたいだけです。 期待どおりに動作しません。 RecyclerViews(私のAppBarLayout)以外のビューをタッチするとスクロールが開始されますが、RecyclerViewsの1つの中でスクロールしようとすると、そのスクロールはもう機能しなくなります。タッチイベントをメインビューに渡す必要がありますか、それとも他の解決策がありますか?スクロール可能な親を持つ非スクロール可能なRecyclerView

私のレイアウトは、この(剥奪)のようになります。

<android.support.design.widget.AppBarLayout> 

    <android.support.design.widget.CollapsingToolbarLayout> 

     <RelativeLayout> 

      <ImageView> 

      <LinearLayout> 

       <TextView /> 

       <TextView /> 

      </LinearLayout> 

     </RelativeLayout> 

     <android.support.v7.widget.Toolbar /> 

    </android.support.design.widget.CollapsingToolbarLayout> 

</android.support.design.widget.AppBarLayout> 

<LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <Button /> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:clipToPadding="false" 
      android:scrollbars="none" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <Button /> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:clipToPadding="false" 
      android:scrollbars="none" /> 

    </LinearLayout> 
</LinearLayout> 

編集:ちょうど絵を追加しました。赤い部分に触れるとアクティビティ全体がスクロールしますが、青い部分に触れても何もスクロールしません。 enter image description here

+0

は私の答えをお試しください〜するのに役立ちます。これがあなたを助けることを願って – FAT

答えて

1
  1. あなたButtonRecyclerViewレイアウトのコンテナとしてNestedScrollViewを使用してください。
  2. セットapp:layout_behavior="@string/appbar_scrolling_view_behavior"からNestedScrollView
  3. CoordinatorLayoutをルートレイアウトとして使用します。

このような構造をしてみてください。

<android.support.design.widget.CoordinatorLayout> 

<android.support.design.widget.AppBarLayout> 
    <android.support.design.widget.CollapsingToolbarLayout> 
     <RelativeLayout> 
      <ImageView> 
      <LinearLayout> 
       <TextView /> 
       <TextView /> 
      </LinearLayout> 
     </RelativeLayout> 
     <android.support.v7.widget.Toolbar /> 
    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

      <Button /> 

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:clipToPadding="false" 
       android:scrollbars="none" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 

      <Button /> 

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:clipToPadding="false" 
       android:scrollbars="none" /> 

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

</android.support.design.widget.CoordinatorLayout> 

希望これは

2

使用RecyclerView NestedScrollView

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

<android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:nestedScrollingEnabled="false" /> 

<android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:nestedScrollingEnabled="false" /> 


    </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 
+0

私の質問を画像で更新しました。あなたの答えはまだ有効ですか? – Chris

+0

私はあなたの質問を正しく理解していればそれはすべきです。 NestedScrollViewでコンポーネントをすべて確認してください –

0

オーバーライドonInterceptTouchEventメソッド内とtrueを返します。これにより、子どもたちはタッチイベントを処理しなくなります。

@Override 

public boolean onInterceptTouchEvent(MotionEvent ev) 
{ 
    return true; 
} 
関連する問題