I'm trying to implement the swipe gesture on a layout. Here is the 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" >
<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>
In the java code, I set the setOnTouchListener
for the ViewSwitcher
, returning the boolean returned by the GestureDetector
. So I override the onFling
method and actually it works. The only problem is that it works if I'm not touching the Imageviews.
The ImageViews are listening for the onClick
event.
So, how can I swipe on the Imageviews and still recall the code inside the onFling
method?
I tried to set the onTouchListener
even fot he ImageViews but they don't catch the onCLick
event anymore.