gpt4 book ai didi

java - 将按钮放在 google map API 的右上角

转载 作者:行者123 更新时间:2023-12-02 03:13:35 25 4
gpt4 key购买 nike

我无法弄清楚如何在 Google map Activity 的屏幕右上角放置按钮 我是 Android 开发新手,无法找到有关如何执行此操作的直接说明。我的主要 Activity 代码如下所示:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private final LatLng LOWER_WEST_BOUND = new LatLng(45.427882, 13.347119);
private final LatLng UPPER_EAST_BOUND = new LatLng(46.904552, 16.664808);
private final LatLng LJUBLJANA = new LatLng(46.052771, 14.503602);
private final LatLngBounds SLOVENIJA_OUTER_BOUNDS = new LatLngBounds(LOWER_WEST_BOUND, UPPER_EAST_BOUND);

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}


/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

mMap.setLatLngBoundsForCameraTarget(SLOVENIJA_OUTER_BOUNDS);
mMap.addMarker(new MarkerOptions().position(LJUBLJANA).title("Marker in Ljubljana"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LJUBLJANA, 15));
}

}

所需的应用外观:

/image/n2FXF.png

我的 .xml 文件如下所示:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.fri.studentskaprehrana.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="@layout/place_autocomplete_fragment" />

最佳答案

要放置图标的位置位于操作栏中。要将菜单项放置在那里,请参阅 the menu docs

对于菜单,请尝试:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_button"
android:icon="@drawable/buttonIcon"
app:showAsAction="always"
android:title="Button title" />
</menu>

关于java - 将按钮放在 google map API 的右上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40683236/

25 4 0