views:

67

answers:

2

I have a flipper:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/ParentLayout"
    xmlns:android="http://schemas.android.com/apk/res/android" style="@style/MainLayout" >
            <LinearLayout android:id="@+id/FlipperLayout" style="@style/FlipperLayout">
                <ViewFlipper android:id="@+id/viewflipper" style="@style/ViewFlipper">
                    <!--adding views to ViewFlipper-->
                    <include layout="@layout/home1" android:layout_gravity="center_horizontal" />
                    <include layout="@layout/home2" android:layout_gravity="center_horizontal" />
                </ViewFlipper>
            </LinearLayout>
</LinearLayout>

The first layout,home1, consists of a scroll view. What should I do to distinguish between the flipping gesture and the scrolling? Presently:

  • if I remove the scroll view, I can swipe across
  • if I add the scroll view, I can only scroll.

I saw a suggestion that I should override onInterceptTouchEvent(MotionEvent), but I do not know how to do this. My code, at this moment, looks like this:

public class HomeActivity extends Activity {
-- declares
@Override
public void onCreate(Bundle savedInstanceState) {
    -- declares & preliminary actions

    LinearLayout layout = (LinearLayout) findViewById(R.id.ParentLayout);
    layout.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }});

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    gestureDetector.onTouchEvent(event); 
    return true;
    }
class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    // http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/
    }
}

}

Can anybody please guide me in the right direction?

Thank you.

+1  A: 

The view flipper only displays one view at a time as explained here. It is a kind of switch that is very useful when the developer wants to give the user a choice as to how to view the data (list, thumbnails, ect). therefore, the reason why you cant scroll and fling at the same time is because one view only scrolls and the other view only flings and only one is open at a time.

If you want your display to both scroll and fling, you will have to design a layout that is capable of both and override the needed methods. The first step towards that would be to remove your ViewFLipper and use something else.

Hope this was helpful!

mtmurdock
Thank you for your very quick answer. As a matter of fact I was thinking of a way to capture the motion event at the ParentLayout level (the one that encloses the flipper) and decide at that level whether the gesture is a horizontal one (to be taken into account by the flipper) or a vertical one (to be passed to the scroll view).That's why the onInterceptTouchEvent seemed to me the right one.So there is no way to achieve what I had in mind?
Manu
I guess perhaps im not entirely sure what you are trying to achieve. what are home1 and home2, and what is each gesture supposed to accomplish? what is your app supposed to do?
mtmurdock
The home1 and home2 layouts contain each a number of image buttons, each image button triggers an activity. home1 and home2 are included in a layout called home, the one hosting the flipper. Now: when the user swipes accross I need to display the next home<x> layout, which is done by the flipper. But since their are many image buttons, when the phone is in landscape mode they do not fit on screen all of them, so I need to scroll, the home1 layout.
Manu
ok i get it. well there is no reason why you shouldnt be able to do that. i think you're layout is probably right, you just need to properly implement the gesture code. i think you're on the right track too, but i dont know anything about gestures... sorry.
mtmurdock
A: 

I have the same problem. Did you find a solution?

Abid
As a matter of fact there I implemented a workaround: I added a title on top of the flipper: when swipping over the title I get a fling (H), when over the flipper I get the scroll (V). As mtmurdock explained earlier, there is no possibility to have both in the same time. HTH.
Manu