0

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.

Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71
  • First the `ViewSwitcher` is a "`ViewAnimator` that switches between **two views**". If you want more views you should use a `ViewFlipper`. And the only thing that is inside that views should be the content that is swiped. If you do that, you won't have problems. – Diogo Bento Apr 17 '13 at 17:11
  • Actually I need to switch among two views. And the content (the six ImageViews) is the one I need to swipe. – Daniele Vitali Apr 17 '13 at 17:51

1 Answers1

0

on the ViewSwitcher put the layouts as wrap_content like this:

<ViewSwitcher
    android:id="@+id/switcher"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/blister_background" >
Diogo Bento
  • 197
  • 2
  • 13