android - 工具栏未出现或上面有 MapFragment

标签 android android-5.0-lollipop

我正在尝试将我的 ActionBar 迁移到 AppCompat 21 方式(使用设置为用作 ActionBar 的工具栏小部件),但它没有显示或被 MapFragment 隐藏。

这是我的 Activity :

<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="com.br.myapp.fragments.MapFragment">

    <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:dragView="@+id/name"
        sothree:fadeColor="@android:color/transparent"
        sothree:panelHeight="0dp"
        sothree:paralaxOffset="100dp"
        sothree:shadowHeight="3dp">

        <!-- MAIN CONTENT -->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                xmlns:sothree="http://schemas.android.com/apk/res-auto"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/main_toolbar"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                sothree:theme="@style/MyApp.Widget.ActionBar.Solid"
                android:layout_width="match_parent"/>

            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.br.myapp.MapActivity" />
        </FrameLayout>



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#99ffffff"
            android:clickable="false"
            android:focusable="false"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/linear_layout_anchor_area"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:orientation="vertical"
                android:padding="10dp">

                <TextView
                    android:id="@+id/text_park_name"
                    style="@style/MyApp.TextName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/placeholder_park_name"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/text_park_address"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/placeholder_park_address"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/textParkAddressCaption"
                    style="@style/MyApp.Text.MoreInformation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/label_more_information"
                    android:textAppearance="?android:attr/textAppearanceSmall" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#cccccc"
                android:orientation="vertical"></LinearLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="140dp"
                android:minHeight="100dp"
                android:padding="10dp">

                <ImageView
                    android:id="@+id/imageThumbnail"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:src="@drawable/default_image_park_preview" />

                <RelativeLayout
                    android:id="@+id/dailyRateArea"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="false"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="8dp"
                    android:layout_toRightOf="@+id/imageThumbnail">

                    <Button
                        android:id="@+id/button_call"
                        style="@style/MyApp.Button.Call"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:layout_alignParentTop="true"
                        android:text="@string/button_call" />

                    <RelativeLayout
                        android:id="@+id/nightlyRateArea"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_alignParentBottom="false"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentStart="false"
                        android:layout_below="@+id/button_call"
                        android:layout_marginBottom="4dp"
                        android:layout_marginTop="8dp"
                        android:background="#cccccc">

                    </RelativeLayout>

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="false"
                        android:layout_below="@+id/nightlyRateArea"
                        android:layout_marginTop="8dp"
                        android:background="#cccccc"
                        android:orientation="horizontal">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginRight="1dp"
                            android:layout_weight="1"
                            android:background="#ffffff"
                            android:paddingBottom="4dp"
                            android:paddingTop="4dp">

                            <ImageView
                                android:id="@+id/imageIconDistance"
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:layout_alignParentTop="true"
                                android:layout_centerHorizontal="true"
                                android:src="@drawable/ic_pin_park_preview" />

                            <TextView
                                android:id="@+id/textViewDistance"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentBottom="true"
                                android:layout_centerHorizontal="true"
                                android:gravity="center"
                                android:text="0m"
                                android:textAppearance="?android:attr/textAppearanceSmall" />
                        </RelativeLayout>

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginRight="1dp"
                            android:layout_weight="1"
                            android:background="#ffffff"
                            android:paddingBottom="4dp"
                            android:paddingTop="4dp">

                            <ImageView
                                android:id="@+id/imageIconAvailableSpots"
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:layout_alignParentTop="true"
                                android:layout_centerHorizontal="true"
                                android:src="@drawable/ic_available_spots" />

                            <TextView
                                android:id="@+id/textViewAvailableSpots"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentBottom="true"
                                android:layout_centerHorizontal="true"
                                android:text="-"
                                android:textAppearance="?android:attr/textAppearanceSmall" />
                        </RelativeLayout>

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:background="#ffffff"
                            android:paddingBottom="4dp"
                            android:paddingTop="4dp">

                            <TextView
                                android:id="@+id/textViewPriceLabel"
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:layout_alignParentTop="true"
                                android:layout_centerHorizontal="true"
                                android:text="$/h"
                                android:textColor="#cccccc"
                                android:textSize="19sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/textViewPrice"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentBottom="true"
                                android:layout_centerHorizontal="true"
                                android:text="-"
                                android:textAppearance="?android:attr/textAppearanceSmall" />
                        </RelativeLayout>
                    </LinearLayout>
                </RelativeLayout>

            </RelativeLayout>

        </LinearLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>

最佳答案

FrameLayout 中的元素排序(以及 API 21+ 中的高度和 z 平移)定义了 z 排序。您将 Toolbar 元素定位在内容 fragment 之前,该元素设置为在两个维度上都与父级匹配,因此 Toolbar 完全被内容 fragment 覆盖。

试试下面的方法,它只是颠倒顺序:

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.br.myapp.MapActivity" />

        <android.support.v7.widget.Toolbar
            xmlns:sothree="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/main_toolbar"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            sothree:theme="@style/MyApp.Widget.ActionBar.Solid"
            android:layout_width="match_parent"/>
    </FrameLayout>

关于android - 工具栏未出现或上面有 MapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161186/

相关文章:

java - 获取不同运营商的Cell ID

android - 如何在android中使用put方法向HTTPBody添加数据

java - 如何将时间戳插入 SQLite 数据库列?使用函数时间 ('now' )?

Android:以编程方式遍历资源 ID

java - Pre L中的Android L Elevation Effect(仅使用elevation属性)

java - Google 登录不适用于已发布的应用

android - 自定义 PagerTabStrip 如何通过单击禁用切换选项卡 - 不起作用

android-5.0-lollipop - Android BLE 特性读/写在 Lollipop 中失败,但在 Kitkat 中工作

android - 在 Android 5.0 中通过 NFC 激活设备所有者期间无法连接 Wifi

android - 抽屉导航在状态栏上半透明不起作用