Я пытаюсь создать приложение для карт, которое может принять ваше местоположение и в то же время сохранить ваши маркеры.
Но у меня возникают проблемы при попытке добавить FloatingButton
в то же время.
Это мой content_main.XML
с LoactionButton , а XML предыдущего:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="13"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#FFFFFF"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
Я был заменен LinearLayout
элементом на RelativeLayout
, потому что пытаясь FloatingButton
в content_main.xml
я получаю следующий . Предыдущее изображение. xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="13"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#FFFFFF"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="180dp"
android:backgroundTint="#FFF"
android:clickable="true"
android:focusable="true"
app:fabSize="normal">
</com.google.android.material.floatingactionbutton.FloatingActionButton>
</LinearLayout>
Поэтому, просматривая множество примеров в Google, я увидел, что некоторые люди используют RelativeLayout
для добавления FloatingButton
в основной контент. Я решил изменить на RelativeLayout
, но LocationButton
недоступно, как этот предыдущий. xml следующий и фактический:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="13"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#FFFFFF"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="180dp"
android:backgroundTint="#FFF"
android:clickable="true"
android:focusable="true"
app:fabSize="normal">
</com.google.android.material.floatingactionbutton.FloatingActionButton>
</RelativeLayout>
Я ищу много примеров, и я изменил свой content_main.xml
, но у меня нет решений поставить кнопку местоположения с помощью FloatingButton.
как можно добавить FloatingButton
с моими фактическими LocationButton
?
РЕДАКТИРОВАТЬ: это мой ButtonLocation
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap //Princiapal Map Variable
mMap.setOnMarkerClickListener(this) //Location Marker
mMap.uiSettings.isZoomControlsEnabled = true //Zoom in maps enabled
mMap.uiSettings.isMyLocationButtonEnabled = true
setUpMap() //Function to detect actual location
}
РЕДАКТИРОВАТЬ ИЗОБРАЖЕНИЕ:
Это мой фактический Макет макета с Это. xml. Но теперь у меня есть проблема с Toolbar Widget
.