Rotate MapView in Android

后端 未结 5 1695
生来不讨喜
生来不讨喜 2020-11-29 02:47

I am writing an Android app where one of the features is that the map will rotate according to the compass (i.e. if the phone is pointing east, the map will be oriented so t

5条回答
  •  时光取名叫无心
    2020-11-29 03:00

    From the docs:

    protected void dispatchDraw (Canvas canvas)

    Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

    So overriding dispatchDraw is no good as the main map view has already been drawn

    One solution might be to add the MapView as a child of another CustomView (a sub-class of ViewGroup) and then use the dispatchDraw method of CustomView to draw the MapView (now a child) rotated. So in xml you'd do something like:

    
    
    
      
    
        
    
      
    
    

提交回复
热议问题