【问题标题】:Make google map not full screen android app使谷歌地图不是全屏安卓应用
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多