gpt4 book ai didi

java - 更改 Google Maps API 的 "My location"按钮的位置

转载 作者:IT老高 更新时间:2023-10-28 11:40:53 25 4
gpt4 key购买 nike

我正在使用 Google Maps Android API v2,我需要一种方法来确定“我的位置”按钮的位置。

我得到这样的“我的位置”按钮:

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

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

最佳答案

您可以获取“我的位置”按钮并移动它,例如:

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);
}
}

关于java - 更改 Google Maps API 的 "My location"按钮的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14489880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com