使谷歌Map不是全屏的Android应用程序

eyh26e7m  于 11个月前  发布在  Android
关注(0)|答案(2)|浏览(116)

我正在尝试实现一个应用程序,它显示了一个Map,在它下面有几个文本字段和几个按钮。
但是当我打开应用程序时,整个屏幕空间都被Map占据了。有没有一种方法可以让所有的对象都很好地填充屏幕而不隐藏一个?
下面是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" />

字符串
我已经尝试将Map的宽度和高度从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);
            }
        });
    } 
}


任何帮助将不胜感激。

avwztpqn

avwztpqn1#

尝试使用LinearLayout和weights:

<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>

字符串
根据您的需要更改重量。
更多关于重量的信息:http://developer.android.com/guide/topics/ui/layout/linear.html#Weight

bwntbbo3

bwntbbo32#

构建>清理项目并再次运行。它对我很有效。

相关问题