我正在使用回收器视图滑动来解散,而我的cardview或recyler项目包含水平滚动视图。每次触摸都会提供滑动以解散的优先权。这是我的代码......请告诉我们如何分开两个滑动?
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_feed_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/activity_feed_image_layout"
android:layout_alignParentLeft="true"
android:layout_margin="@dimen/five_dp"
android:orientation="horizontal">
<com.workplains.androidapp.workmatec.LibraryClasses.CircularImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/image1"
android:id="@+id/task_feed_image" />
</LinearLayout>
<TextView
android:id="@+id/activity_feed_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:layout_alignTop="@id/activity_feed_image_layout"
android:text="9:15 PM"
android:layout_margin="@dimen/five_dp"
android:textSize="12sp"
android:textColor="@color/actionbar_color" />
<TextView
android:id="@+id/task_feed_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Task By WorkMatec"
android:padding="@dimen/two_dp"
android:layout_alignTop="@id/activity_feed_image_layout"
android:layout_toRightOf="@+id/activity_feed_image_layout"
android:layout_toLeftOf="@id/activity_feed_timestamp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textSize="15sp" />
<TextView
android:id="@+id/task_feed_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Task Description by the workmatec. New Task TAsk by the workmatec"
android:padding="@dimen/two_dp"
android:layout_toRightOf="@+id/activity_feed_image_layout"
android:layout_below="@id/task_feed_title"
android:textColor="@android:color/black"
android:textSize="15sp" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/task_feed_attachments"
android:focusableInTouchMode="true"
android:accessibilityLiveRegion="polite"
android:layout_toRightOf="@+id/activity_feed_image_layout"
android:layout_below="@id/task_feed_desc">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bt_ic_imageplaceholder"
android:tint="@color/red"
android:tintMode="src_in" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bt_ic_imageplaceholder"
android:tint="@color/red"
android:tintMode="src_in" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
答案 0 :(得分:1)
在代码中,您必须向OnTouchListener
添加HorizontalScrollView
。然后,当它收到ACTION_MOVE
事件时,您可以禁止父视图(在这种情况下为RecyclerView
)捕获水平滚动移动作为滑动:
HorizontalScrollView hScroll = [findViewById or whatever];
hScroll.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
}
return false;
}
});
请注意,在HorizontalScrollView
的内容未填满整个单元格宽度(因此不激活水平滚动)的情况下,您可能不希望禁止滑动。您可以通过使用检查宽度条件的布尔值更改true
来解决此问题,例如:
horizontalScrollContents.measure(0, 0);
boolean lockSwipe = horizontalScrollContents.getMeasuredWidth() > cellWidth;
...
v.getParent().requestDisallowInterceptTouchEvent(lockSwipe);