Domanda

I have an Activity with a SlidingPaneLayout, and inside there are two fragments: a ListView on the left, and a MapFragment on the right. How is it possible to intercept the touch event generated so that the user can move the map without close the panel?

The only area that I would like to use to close/open the right panel is the first fourth. On the right of that area I would like to move the map.

Thanks

EDIT2:

Ok, now I figured out how to properly subclass SlidingPaneLayout, now the problem is how to capture correctly the touch event:

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN
            && event.getX() > (getWidth() / 6)) {
        return false;
    }
    return super.onTouchEvent(event);
}

With this code I'm not able to slide the map, it remains fixed. the problem is that I want to intercept the touch ONLY when the right panel is selected (in other words, only when map is displayed).

È stato utile?

Soluzione

SlidingPaneLayout have it's own touch listener, so when you reset it by calling setOnTouchListener (which is a method from the super class View) you are loosing all the onTouch behaviour specific to a SlidingPaneLayout.

-------------------------------

Here is a try : make your own SlidingPaneLayout :
the constructor should be this way in order to use your view in an xml layout

public class MySlidingPaneLayout extends SlidingPaneLayout{

    public MySlidingPaneLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        if (event.getX() < widthPIX / 6) {
             return super.onTouchEvent(event);// here it works as a normal SlidingPaneLayout
        }
        return false; // here it returns false so that another event's listener should be called, in your case the MapFragment listener
    }
}

and in your code add MySlidingPaneLayout instead

Altri suggerimenti

I finally solved the problem: simply override this method and control if the SlidingPaneLayout is closed or open (in my case I have a boolean field value "open")

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!homeActivity.open && event.getX() > (getWidth() / 5)) {
            return false;
        }
    return super.onInterceptTouchEvent(event);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top