我在ViewPager中有兩個選項卡,每個選項卡都包含一個RecyclerView,它們基本上是垂直的ListView。我的問題是我無法垂直滾動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);
}
發佈您的代碼。 –
看看這個http://stackoverflow.com/questions/35082043/android-scrolling-issues-with-re-cyclerview-inside-a-viewpager –