Android:在FragmentTransactions中未遵循Elevation

6

我有一个类似以下的布局:

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

我希望设置工具栏和滑动选项卡的高度都为4dp,这样工具栏不会对选项卡产生阴影,但实际上它确实有阴影。我不想在代码中设置工具栏的高度 - 有没有办法防止工具栏产生阴影?我原以为由于两个视图都处于4dp高度,即使它们不在同一个布局中,也不会产生阴影。感谢您的帮助。

这是Android bug的票据链接:https://code.google.com/p/android/issues/detail?id=82041 - Stanislav
1个回答

7

阴影遵循兄弟元素的高度,但不遵循堂兄弟。操作栏和 SlidingTabLayout 不是兄弟元素,因此操作栏会在 SlidingTabLayout 上投下阴影。

如果您不想要阴影,则需要自定义操作栏以去除其高度。


啊,我也想到了 - 所以这是预期的行为?你有文档来源吗?谢谢。 - MattWilliams89
1
抱歉,我的来源是作者。我相信这是一种性能优化。很快你就可以看到源代码,并查看ViewGroup.dispatchDraw()。 - George Mount

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接