android - map in listview header

2019-05-23 04:48发布

问题:

In my app i have an activity which contains a image and a list view at the bottom. Following are the things to be done in the activity.

1. the image view at the top of the page must be of swipe type to show other images.
2. when the list view gets scrolled the image must get moved along with it.
3. in the same activity i have a button, when the button is clicked the image must be switcher over to be a mapview.

What i have done is,

1. I have the image view and mapview in view switcher of a separate layout named as header
2. The header layout is been added in the list view header part.

Now the while the list view is scrolled, the header part gets scrolled along with it, in the same when the view gets switched i am able to switch between image view and map view. But the map is seems to be a fixed one and cannot be moved to see various points

how to move inside the map view of list view header.

回答1:

This is an example but not the solution. In this example I've made a custom scrollview which returns false when scrolled in the x-direction (indicating that the event haven't been handled and should be passed on to the next view):

public class CustomScrollView extends ScrollView {
    private GestureDetector mGestureDetector;
    View.OnTouchListener mGestureListener;

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mGestureDetector = new GestureDetector(new YScrollDetector());
        setFadingEdgeLength(0);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
    }

    // Return false if we're scrolling in the x direction  
    class YScrollDetector extends SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if(Math.abs(distanceY) > Math.abs(distanceX)) {
                return true;
            }
            return false;
        }
    }
}

You need to do something similar in a certain region of your viewswitcher. So you need to modify the basic viewswitchercomponent and make your own variant.

As an alternative to the above suggestion I'd consider not doing it. If you look at apps around using maps this is really not a normal behavior and I doubt it'll run very smooth or make a good user interaction. Maps in general works best when they get as much space as possible. Take a look at some basic map apps: Google Navigation, Google Maps, Google latitude, Yelp.