我想要水平列表。滚动内部没有问题,直到我将onClick添加到viewHolder。然后,只有从左向右滚动时,recyclerview才能工作。要从左向右滚动,我必须将手指放在recyclerview向右移动,然后我可以向左滚动。如果我开始向左滚动抽屉将关闭。如何在此特定视图中禁用抽屉的scoll侦听器?
我的主要布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="5dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/drawer"
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:clickable="true"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerVerticalList"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
和recyclerview adapeter的一部分
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = layoutInflater.from(parent.getContext()).inflate(resourceId, parent, false);
ViewHolder vh = new ViewHolder(view, new ViewHolder.ViewHolderClicks() {
@Override
public void onRVItemClick(String title, int ID) {
//...
}
});
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.title.setText(...);
}
static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView title;
public ViewHolderClicks mListener;
public int ID;
public ViewHolder(View viewItem, ViewHolderClicks mListener) {
super(viewItem);
title = (TextView) viewItem.findViewById(R.id.title);
this.mListener = mListener;
viewItem.setOnClickListener(this);
}
@Override
public void onClick(View v) {
mListener.onRVItemClick(title.getText().toString(), ID);
}
public static interface ViewHolderClicks {
public void onRVItemClick(String title, int ID);
}
}