我正在尝试制作一个左右可刷卡系统(如Tinder),卡上有一个NestedScrollView.目标是如果用户仅向上和向下滑动,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>
Run Code Online (Sandbox Code Playgroud)
(我使用的卡库是https://github.com/wenchaojiang/AndroidSwipeableCardStack)
compile 'com.github.wenchaojiang:AndroidSwipeableCardStack:0.1.5'
Run Code Online (Sandbox Code Playgroud)
当我在NestedScrollView上放置margin_top并在该边距内触摸时,CardStack正确地抓取我的输入并且卡片向左或向右移动,但是如果我触摸并拖动其他任何地方,NestedScrollView会抓住我的输入而不管方向.
我应该扩展/覆盖哪个类/ onTouchEvent以产生这种效果,或者可能有更简单的方法?
谢谢!
android android-custom-view ontouchlistener touch-event android-nestedscrollview
尝试构建一个带有collapsingtoolbarlayout和视图元素的Android应用程序,该视图元素始终直接位于工具栏底部的下方.
我想我只是在整个appbarlayout中弄乱我的组织,但我似乎无法弄清楚正确的排序.
任何帮助都会很棒!谢谢-
这是我的Activity xml
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="244dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/CollapsedTheme"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="center|bottom"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleMarginEnd="20dp"
app:expandedTitleMarginStart="20dp"
app:expandedTitleTextAppearance="@style/ExpandedTheme"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="@style/ToolbarColoredBackArrow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_product" />
Run Code Online (Sandbox Code Playgroud)
而我正试图加入
<RelativeLayout
android:layout_below="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue"/>
Run Code Online (Sandbox Code Playgroud)
因此它始终保持在工具栏下方,但是当collapsingtoolbarlayout滚动到屏幕顶部时,它会一直停留在屏幕下方.