如何更改地图API的&QUOT的位置;把我的位置"钮 [英] How to change the position of maps api's "Get my location" button

查看:218
本文介绍了如何更改地图API的&QUOT的位置;把我的位置"钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是谷歌地图Android的API V2,我需要一种方法来机会的我的位置按钮的位置。

我得到的我的位置按钮,这样的:

  GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
最后的GoogleMap的地图=((SupportMapFragment)getSupportFragmentManager()
        .findFragmentById(R.id.map))的GetMap()。

//这得到了按钮
map.setMyLocationEnabled(真正的);
 

解决方案

您可以得到我的位置按钮,然后移动它,如:

 公共类MapFragment扩展SupportMapFragment {
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
    查看图形页面= super.onCreateView(充气,容器,savedInstanceState);

    //获取按钮来查看
    查看locationButton =((查看)mapView.findViewById(1).getParent())findViewById(2)。

    //和未来的地方它,因为为例,在右下角(如谷歌地图应用程序)
    RelativeLayout.LayoutParams RLP =(RelativeLayout.LayoutParams)locationButton.getLayoutParams();
    //右边底部位置
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
    rlp.setMargins(0,0,30,30);
    }
}
 

I am using the Google Maps Android API v2, and I need a way to chance the position of the "My Location" button.

I get the "My Location" button like this:

GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
        .findFragmentById(R.id.map)).getMap();

// This gets the button
map.setMyLocationEnabled(true);

解决方案

You can get the "My Location" button and move it, like :

public class MapFragment extends SupportMapFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mapView = super.onCreateView(inflater, container, savedInstanceState);   

    // Get the button view 
    View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);

    // and next place it, for exemple, on bottom right (as Google Maps app)
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
    // position on right bottom
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    rlp.setMargins(0, 0, 30, 30);
    }
}

这篇关于如何更改地图API的&QUOT的位置;把我的位置"钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆