Android “上的刷卡事件”;复杂的;布局
我试图在布局上实现滑动手势。以下是xml:Android “上的刷卡事件”;复杂的;布局,android,swipe-gesture,Android,Swipe Gesture,我试图在布局上实现滑动手势。以下是xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blister_background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum=".9" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".3"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="@+id/imgOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
<ImageView
android:id="@+id/imgTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".3"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="@+id/imgThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
<ImageView
android:id="@+id/imgFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".3"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="@+id/imgFive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
<ImageView
android:id="@+id/imgSix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="@drawable/yellow" />
</LinearLayout>
</LinearLayout>
</ViewSwitcher>
</RelativeLayout>
在java代码中,我为ViewSwitcher
设置了setOnTouchListener
,返回GestureDetector
返回的布尔值。所以我重写了onFling的onFling
方法,实际上它是有效的。唯一的问题是,如果我不接触ImageView,它就会工作
ImageView正在侦听onClick
事件
那么,我如何在ImageView上滑动,仍然能够调用onFling
方法中的代码呢
我尝试将
设置为TouchListener
甚至是图像视图,但它们不再捕捉onCLick
事件。在视图切换器上将布局设置为wrap\u content,如下所示:
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/blister_background" >
首先,ViewSwitcher
是一个“viewmanimator
在两个视图之间切换”。如果需要更多视图,应使用视图翻转器
。视图中唯一的东西应该是被刷过的内容。如果你这样做,你就不会有问题。实际上我需要在两个视图之间切换。内容(六个图像视图)就是我需要刷的内容。