【发布时间】:2023-03-17 14:43:01
【问题描述】:
我正在尝试实现一个显示地图的应用,该地图下有几个文本字段和几个按钮。
但是当我打开应用程序时,整个屏幕空间都被地图占据了。有没有办法让所有对象都很好地填满屏幕而不隐藏一个?
这是来自 activity_main xml 文件的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment"/>
<EditText android:id="@+id/EditTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/EditTest" />
<EditText android:id="@+id/inTegerTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/integerTest" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ButtonTest" />
我已经尝试将地图的宽度和高度从 match_parent 更改为 wrap_content,但仍然无法正常工作。
这是来自activity_main的代码:
private GoogleMap mMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getMapSafely();
if(mMap != null){
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
// This will be displayed on taping the marker
markerOptions.title(latLng.latitude + " : " + latLng.longitude);
// Clears the previously touched position
mMap.clear();
// Animating to the touched position
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
// Placing a marker on the touched position
mMap.addMarker(markerOptions);
}
});
}
}
任何帮助将不胜感激。
【问题讨论】:
标签: java android xml google-maps