【发布时间】:2017-11-30 18:33:01
【问题描述】:
问题
我在 ViewPager 内的 NestedScrollView 中有一个水平 RecyclerView。现在,当我尝试滚动 RecyclerView 时,有时它会滚动,但有时只有 ViewPager 滚动。
代码
这就是我的 RecyclerView XML 的样子:
<android.support.v7.widget.RecyclerView
android:id="@+id/sidescroll"
android:layout_below="@+id/movie_more_movies2"
android:layout_marginTop="@dimen/material_layout_keylines_horizontal_margin"
android:layout_marginBottom="@dimen/material_layout_keylines_horizontal_margin"
android:layout_width="match_parent"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:layout_height="wrap_content"/>
这就是 RecyclerView 所在的 Nested Scroll 的样子:
<android.support.v4.widget.NestedScrollView
android:id="@+id/detail_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:descendantFocusability="blocksDescendants"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
这是viewpager xml:
<com.mt.moviesiwanttowatch.ui.ViewPagerWithHorizontalRecyclerView
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
我正在使用这个自定义 ViewPager:
public class ViewPagerWithHorizontalRecyclerView extends ViewPager {
public ViewPagerWithHorizontalRecyclerView(Context context) {
super(context);
}
public ViewPagerWithHorizontalRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if(v instanceof RecyclerView){
Log.e("PAGER", "IS");
return false;
} else {
Log.e("PAGER", "IS NOT " + v.toString());
}
return super.canScroll(v, checkV, dx, x, y);
}
}
我的方法
到目前为止我所尝试的,如您所见,我编写了一个自定义 ViewPager。我试图告诉 ViewPager,如果滚动来自 RecyclerView,它就无法滚动。但是这不起作用。
日志:
这是 ViewPager 滚动而不是 RecyclerView 滚动时的日志
> 06-27 17:50:53.506 32362-32362/com.mt.moviesiwanttowatch E/PAGER: IS NOT
> com.mt.moviesiwanttowatch.ui.ViewPagerWithHorizontalRecyclerView{c506165
> VFED..... ........ 0,341-1080,1794 #7f090287 app:id/viewpager}
> 06-27 17:50:53.506 32362-32362/com.mt.moviesiwanttowatch E/PAGER: IS NOT android.support.v4.widget.NestedScrollView{d21952 VFED.....
> ........ 0,0-1080,1453 #7f0900b9 app:id/detail_holder}
> 06-27 17:50:53.506 32362-32362/com.mt.moviesiwanttowatch E/PAGER: IS NOT android.widget.RelativeLayout{6ddeec0 V.E...... ........
> 0,0-1080,2860 #7f090199 app:id/movie_overview_holder}
> 06-27 17:50:53.506 32362-32362/com.mt.moviesiwanttowatch E/PAGER: IS
【问题讨论】:
-
尝试设置 ViewCompat.setNestedScrollingEnabled(recycleView,false);
-
我做了,但没有帮助
标签: java android xml android-layout android-recyclerview