android - 无法获取我的位置和位置按钮不显示

标签 android android-layout android-fragments android-studio material-design

在我制作抽屉菜单和 float 按钮后,为什么我的 map 无法获取我的位置和位置按钮不显示,以及为什么搜索位置按钮在单击时强制停止? 在我添加抽屉菜单和 float 按钮之前,一切都还好..
[pict]BEFORE
[pict]AFTER

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.emergency.MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerLayout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:id="@+id/toolbar">
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:fab="http://schemas.android.com/apk/res-auto"
            android:background="@color/background"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <include layout="@layout/activity_maps"/>

            <com.getbase.floatingactionbutton.FloatingActionsMenu
                android:id="@+id/multiple_actions"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                fab:fab_addButtonColorNormal="@color/white"
                fab:fab_addButtonColorPressed="@color/white_pressed"
                fab:fab_addButtonPlusIconColor="@color/half_black"
                fab:fab_labelStyle="@style/menu_labels_style"
                android:layout_marginBottom="50dp"
                android:layout_marginRight="16dp"
                android:layout_marginEnd="16dp">

                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/action_a"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/white"
                    fab:fab_title="Tambal Ban"
                    fab:fab_colorPressed="@color/white_pressed"
                    fab:fab_size="mini"/>
                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/action_b"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/white"
                    fab:fab_title="ATM"
                    fab:fab_colorPressed="@color/white_pressed"
                    fab:fab_size="mini"/>
                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/action_c"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/white"
                    fab:fab_title="WC Umum"
                    fab:fab_colorPressed="@color/white_pressed"
                    fab:fab_size="mini"/>

            </com.getbase.floatingactionbutton.FloatingActionsMenu>

        </RelativeLayout>
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        app:headerLayout="@layout/header_menu"
        app:menu="@menu/menu_navigasi"
        android:layout_gravity="start">
        <!--perintah buat nampilin menu utama kemudian bisa di slide yang ada menu adalah yang layout_gravity-->


    </android.support.design.widget.NavigationView >
</android.support.v4.widget.DrawerLayout>

activity_maps.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">

    <LinearLayout
        android:id="@+id/header_tempat"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:context="com.emergency.MapsActivity" />
    </LinearLayout>
    <Button
        android:id="@+id/Bsearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff4081"
        android:src="@android:drawable/ic_dialog_map"
        android:text="Search Place"
        android:textColor="#fff"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="onSearch"
        />

</RelativeLayout>

最佳答案

出于某种原因SupportMapFragment放在里面时不显示我的位置按钮(或罗盘图标)<DrawerLayout> (<- 作为 Root View ),但有一个解决方案:

把整个<DrawerLayout><RelativeLayout>并删除 <include>然后把整个 activity_maps.xmlactivity_main .另外为了让它看起来更好,我建议移动 activity_maps.xml并从中制作一个 fragment ,然后代替 <include>你会:

<fragment
    android:id="@+id/map_fragment"
    class="com.yourpackage.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

您将只为 fragment 中的 map 分离逻辑, Activity 中的所有 Activity 内容。我们都知道 MainActivity出于多种原因往往会随着时间的推移而增长 ;)

关于android - 无法获取我的位置和位置按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36985787/

相关文章:

android - 允许嵌套滚动同时允许编辑文本扩展一点(xml)

android - 我们可以用边框包裹 ExpandableListView 的 child 吗

android - ConstraintLayout 内的 ScrollView 不工作

java - 从 MainActivity 的 Button Click 中的 Fragment 访问方法

java - Android-按钮滑动效果

android - fragment后台任务访问资源经常返回illegalStateException

android - 避免在 fragment 中多次传递参数

java - Observable.empty() 导致 java.util.NoSuchElementException : Sequence contains no elements

覆盖有按钮的android TextView

android - 用于获取子字符串的开始和结束索引的 Kotlin 函数