2015-01-27 23 views
2

我正在嘗試將我的ActionBar移植到AppCompat 21的方式(使用設置爲ActionBar的工具欄小部件),但它沒有顯示或隱藏通過MapFragment。工具欄未顯示或其上的MapFragment

這裏是我的活動:的FrameLayout

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

您將它定位在內容FrameLayout中的工具欄之後,這會導致它在上面呈現。 – alanv 2015-01-27 00:32:00

+0

你說得對。你能否將你的評論推薦給答案,以便我能接受它? – 2015-01-27 08:20:04

回答

5

元素排序(隨着海拔的API和z翻譯21+)定義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> 
+0

有史以來最好的答案我已經做了關於這個微小但火焰的問題。 – albanx 2015-12-21 19:11:28

0

只是檢查你的widget是在合適的地方。

<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> 
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(); 
}