2014-11-01 48 views
5
不尊重

所以我有一個佈局,類似於以下內容:安卓:海拔跨越FragmentTransactions

 <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_height="wrap_content" 
      android:elevation="4dp" 
      android:background="?attr/colorPrimary" 
      android:layout_width="match_parent" 
      android:minHeight="?attr/actionBarSize"/> 

     <FrameLayout 
      android:id="@+id/content" 
      android:layout_below="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

    </RelativeLayout> 

這就形成了我的基地佈局文件我的活動,然後我換出的FrameLayout各種碎片。一個這樣的片段具有這樣的佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <SlidingTabLayout 
     android:id="@+id/sliding_tabs" 
     android:layout_width="match_parent" 
     android:elevation="4dp" 
     android:layout_height="wrap_content"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/profileViewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/sliding_tabs" 
     android:background="@android:color/white"/> 

    <FloatingActionButton 
     android:id="@+id/floatingButton" 
     android:layout_width="72dp" 
     android:layout_height="72dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="16dp" 
     android:layout_marginBottom="16dp"/> 

</RelativeLayout> 

我期望我同時設置工具欄和SlidingTabLayout的海拔是4DP,該工具欄不會投下了一片陰影的標籤,但它的作用:

Screenshot

理想的情況下,我不會想成爲設置工具欄的海拔在代碼中 - 沒有人知道是否有一種方法,以防止工具欄投下陰影?我會假設這兩個視圖都處於4dp高度,即使它們不在同一個佈局中,也不會投射陰影。

感謝您的幫助。

+0

這裏是Android bug的票:https://code.google.com/p/android/issues/detail?id=82041 – Stanislav 2017-02-01 08:48:10

回答

5

陰影尊重兄弟姐妹的海拔,但不是堂兄弟。操作欄和SlidingTabLayout不是兄弟,因此操作欄會在SlidingTabLayout上投射陰影。

如果您不需要陰影,您需要自定義操作欄以刪除高程。

+0

啊我想的很多 - 所以這是打算的行爲?你有任何機會從文檔中獲取源代碼嗎? 乾杯 – MattWilliams89 2014-11-04 13:44:31

+1

對不起,我的來源是作者。我相信這是一個性能優化。您將能夠很快看到源代碼,並且您可以查看ViewGroup.dispatchDraw()。 – 2014-11-05 15:18:49