2016-11-29 6 views
0

私はViewPagerの中に2つのタブがあり、各タブは基本的に垂直なリストビューであるRecyclerViewを含んでいます。私の問題は、RecyclerViewsを垂直方向にスクロールできないことです。ここでViewPager内でRecyclerViewをスクロールする方法は?

<com.myapplication.MyViewPager 
    android:layout_below="@+id/music_tabs" 
    android:id="@+id/music_switcher" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 



     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_featured_music" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_device_music" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

</com.myapplication.MyViewPager> 

はMyViewPagerある

public class MyViewPager extends ViewPager { 

public MyViewPager(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 

    int height = 0; 
    for(int i = 0; i < getChildCount(); i++) { 
     View child = getChildAt(i); 
     child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
     int h = child.getMeasuredHeight(); 
     if(h > height) height = h; 
    } 

    heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); 

    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
} 
+1

コードを投稿してください。 –

+0

これをご覧くださいhttp://stackoverflow.com/questions/35082043/android-scrolling-issues-with-recyclerview-inside-a-viewpager –

答えて

2

それは私のonMeasure方法が問題を引き起こしていたようです。それを削除した後、問題は解決しました。

0

次の2つのrecycleviewを使用していて、レイアウトの高さではなく、使用の内容にこのコードをラップまたはDPでlayout_heightを定義しているとおり:

android:layout_height="250dp" 
1

あなたが事前にrecyclerviewの大きさを測定することはできません。 onMeasureを削除した後も正常に動作するはずです。

関連する問題