工具栏未显示或MapFragment未显示

时间:2015-01-27 00:15:03

标签: android android-5.0-lollipop

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

这是我的活动:

<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>

3 个答案:

答案 0 :(得分:6)

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

请尝试以下操作,这只是颠倒了顺序:

    <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>

答案 1 :(得分:0)

只需检查您的小部件是否在适当的位置。

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom" />
</FrameLayout>

答案 2 :(得分:0)

就像常规片段事务一样,准备一个容器,以便稍后使用代码将片段添加到其中:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        style="@style/AppBarLayoutStyle"
        android:background="@color/red"
        android:minHeight="?attr/actionBarSize"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/BlackTitleBarStyle"
            android:background="@android:color/transparent"
            app:titleTextColor="@color/white"/>
    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/map_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

然后在其中添加SupportMapFragment

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = new SupportMapFragment();
    mapFragment.getMapAsync(this);
    getSupportFragmentManager().beginTransaction()
                .add(R.id.map_fragment_container, mapFragment)
                .commit();
}
相关问题