我在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 –