使谷歌地图不是全屏Android应用程序

use*_*470 2 java xml android google-maps

我正在尝试实现一个应用程序,显示一个地图,下面有几个文本字段和几个按钮.

但是当我打开应用程序时,整个屏幕空间都被地图占用.有没有办法让所有对象都能很好地填满屏幕,而不会隐藏一个?

这是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" />
Run Code Online (Sandbox Code Playgroud)

我已经尝试将地图宽度和高度从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);
            }
        });
    } 
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

dth*_*sen 6

尝试使用LinearLayout和权重:

<LinearLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_weight="4"/>

<EditText android:id="@+id/EditTest"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:hint="@string/EditTest"
    android:layout_weight="1"/>

<EditText android:id="@+id/inTegerTest"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:hint="@string/integerTest"
    android:layout_weight="1"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="@string/ButtonTest"
    android:layout_weight="1"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

根据您的需要更改重量.

有关权重的更多信息:http://developer.android.com/guide/topics/ui/layout/linear.html#Weight