无法获取我的位置和位置按钮不显示 [英] can't get my location and location button not show

查看:85
本文介绍了无法获取我的位置和位置按钮不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我创建了抽屉菜单和浮动按钮之后,为什么我的地图无法显示我的位置和位置按钮,为什么单击时单击搜索位置按钮以便停止操作? 在我添加抽屉菜单和浮动按钮之前,一切都很好..

after i make drawer menu and floating button why my maps can't get my location and location button not show, and why the search place button when it clicked so that force stop? before i add drawer menu and floating button, it's all okay..
Before
After

activity_main.xml

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

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>内时(<--作为根视图)不显示我的位置按钮(或罗盘图标). ,但是有一个解决方案:

For some reason SupportMapFragment does not show my location button (or compass icon) when its placed inside <DrawerLayout> (<- as a root view), but there is a solution:

将整个<DrawerLayout>放入<RelativeLayout>中,然后删除<include>,然后将整个activity_maps.xml放入activity_main中.为了使它看起来更好,我建议移动activity_maps.xml并从中制作一个片段,然后代替<include>您将拥有:

Put the whole <DrawerLayout> in <RelativeLayout> and remove <include> and just put whole activity_maps.xml in activity_main. Also to make it look better I would recommend moving activity_maps.xml and make a fragment from it, and then instead of <include> you would have:

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

您将仅对片段中的map(活动中的所有活动内容)使用单独的逻辑.而且我们都知道MainActivity会随着时间的流逝而增长;)

You will have separated logic only for map in the fragment, an all activity stuff in activity. And we all know that MainActivity tends to grow over time for many reasons ;)

这篇关于无法获取我的位置和位置按钮不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆