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

标签 java android xml google-maps

我正在尝试实现一个显示 map 的应用程序, 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);
            }
        });
    } 
}

如有任何帮助,我们将不胜感激。

最佳答案

尝试使用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>

根据您的需要更改权重。

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

关于java - 使谷歌地图不是全屏Android应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26255771/

相关文章:

java - 构造函数执行后的初始化域

java - Spring 表单绑定(bind)到 c 内的 Set :forEach

java - 读取/写入 pbxproj/xcodeproj 文件的库?

java - 无法解析主机名意味着如何在android studio中的异步任务中解析它

android - 将 .java 文件作为 Java 源文件包含在 Android Studio 中,以删除带有 "J"的红色圆圈

c# 使用 XDocument 读取 XML 注释

java - 如何在 Java 中比较字符串?

java - 如何实现可折叠(带 handle )的垂直侧边栏android

c# - 转义时超出字符串长度限制

c++ - 使用 Xerces 验证未定义架构的 XML