我正试图制作一个左右滑动的卡片系统(类似于Tinder),其中卡片上有一个嵌套的ScrollView。目标是如果用户只向上或向下滑动,NestedScrollView会滚动,但如果用户向左或向右滑动,卡片将使用该滑动。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
card_view:cardUseCompatPadding="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v7.widget.CardView>
我正在使用的卡片库是 https://github.com/wenchaojiang/AndroidSwipeableCardStack。
compile 'com.github.wenchaojiang:AndroidSwipeableCardStack:0.1.5'
当我在NestedScrollView上放置margin_top并在该margin内触摸时,CardStack正确地获取我的输入并使卡片向左或向右移动,但是如果我在其他任何地方触摸和拖动,NestedScrollView无论方向都会获取我的输入。
我应该扩展/覆盖哪个类/onTouchEvent来实现这种效果,或者可能有更简单的方法吗?
谢谢!