質問

I have a ListView with com.google.android.gms.maps.MapView in its header. When I'm scrolling the list I want the MapView to be hidden and it works just fine. But, when I'm scrolling the header from up to down, or down up I don't want ListView to perform scrolling - I want it to allow MapView to perform its zoom/scroll operations.
I know that it's bad idea to use ListView/MapView together, but I need to find a solution. I thought about setting the OnTouchListener on the ListView instance and dispatching its events to the MapView when needed but it looks like a not very straightforward solution.

役に立ちましたか?

解決

In the end I've solved it by extending the ListView class:

public class SingleScrollableHeaderListView extends ListView {
    private View mHeaderView;

    public SingleScrollableHeaderListView(Context context) {
        super(context);
    }

    public SingleScrollableHeaderListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SingleScrollableHeaderListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (mHeaderView != null) return mHeaderView.onTouchEvent(ev);
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public void addHeaderView(View v, Object data, boolean isSelectable) {
        if (mHeaderView != null) removeHeaderView(mHeaderView);
        mHeaderView = v;
        super.addHeaderView(v, data, isSelectable);
    }
}

The significant part is the onInterceptTouchEvent() method - here I'm passing the MotionEvent instance to the header view if it exists, otherwise I let the ListView to deal with the motion event.

他のヒント

try calling requestDisallowInterceptTouchEvent(true) to the listview when in OnTouch on the MapView

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top