大佬教程收集整理的这篇文章主要介绍了android – 关于DrawerLayout的Horiziontal recyclerview,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/header" app:menu="@menu/meny" />
headerLayout有一个水平的RecyclerView,它有一些用户可以在其上滚动的项目.
我的问题是每当我想在RecyclerView中滚动时,drawerLayout即将关闭.
有没有办法在Drawerlayout上支持水平RecyclerView?
public class DrawerLayoutHorizontalSupport extends DrawerLayout { private RecyclerView mRecyclerView; private NavigationView mNavigationView; public DrawerLayoutHorizontalSupport(Context context) { super(context); } public DrawerLayoutHorizontalSupport(Context context,AttributeSet attrs) { super(context,attrs); } public DrawerLayoutHorizontalSupport(Context context,AttributeSet attrs,int defStylE) { super(context,attrs,defStylE); } @Override public Boolean onInterceptTouchEvent(MotionEvent ev) { if (isInside(ev) && isDrawerOpen(mNavigationView)) return false; return super.onInterceptTouchEvent(ev); } private Boolean isInside(MotionEvent ev) { //check whether user touch recylerView or not return ev.getX() >= mRecyclerView.getLeft() && ev.getX() <= mRecyclerView.getright() && ev.getY() >= mRecyclerView.getTop() && ev.getY() <= mRecyclerView.getBottom(); } public void set(NavigationView navigationView,RecyclerView recyclerView) { mRecyclerView = recyclerView; mNavigationView = navigationView; } }
在给布局充气后,只需调用set并传递NavigationView和RecyclerView.
在onInterceptTouchEvent我检查抽屉是否打开,用户触摸RecyclerView内部然后我返回false,所以DrawerLayout什么都不做
以上是大佬教程为你收集整理的android – 关于DrawerLayout的Horiziontal recyclerview全部内容,希望文章能够帮你解决android – 关于DrawerLayout的Horiziontal recyclerview所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。