带阴影的弯曲 android 工具栏

Ham*_*han 3 android android-layout android-toolbar cardview

我需要为 Toolbar 或 CardView 提供一个弯曲的底视图。

我试过的:

bg_toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" />
    </item>
    <item
            android:bottom="0dp"
            android:left="-100dp"
            android:right="-100dp"
            android:top="-80dp">
        <shape android:shape="oval">
            <solid android:color="@color/colorAccent" />
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

将此设置为工具栏的背景会使应用栏高度(阴影)无效。此外,如果将此背景应用于 CardView 背景已设置,但阴影不符合背景的形状。

见下图,我希望阴影环绕曲线。

问题在图片中很明显

Kai*_*han 5

我已经使用 arcView 做到了这一点

依赖实现 'com.github.florent37:shapeofview:1.3.2'

<com.github.florent37.shapeofview.shapes.ArcView
        android:layout_width="match_parent"
        android:layout_height="155dp"
        android:elevation="5.0dp"
        app:shape_arc_cropDirection="outside"
        app:shape_arc_height="35dp"
        app:shape_arc_position="bottom">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="155dp"
            android:background="@color/colorPrimary"
            android:elevation="5dp" />

    </com.github.florent37.shapeofview.shapes.ArcView>
Run Code Online (Sandbox Code Playgroud)

检查附加图像

在此处输入图片说明