如何在 API 等级 21 及以上实现顶部阴影效果的最佳方法?

huangapple 未分类评论46阅读模式
英文:

What is the best way to create top shadow targeting API level 21?

问题

我有一个底部弹出窗口,我想实现以下图片效果:

[![点击查看图片描述][1]][1]

目前它的外观是平的,像这样:

[![点击查看图片描述][2]][2]

那么,我该如何在底部弹出窗口上添加一个顶部阴影并使其可滑动?在底部弹出窗口中,我有一个线性布局用作背景,例如:

<!-- 这是应用了 BottomSheetBehavior 的背景内容 -->
<LinearLayout
    android:id="@+id/contentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:behavior_peekHeight="356dp"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

    <!-- 这是带有标题和图标的背景头部 -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:background="@drawable/front_backdrop_top"
        android:layout_height="90dp">
    </RelativeLayout>

    <!-- 最后,这是背景内容的主体部分 -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="8dp"
        app:elevation="8dp"
        android:background="@drawable/fron_backdrop_main"
        android:paddingStart="28dp">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/fs_rv_search"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>

    </RelativeLayout>

</LinearLayout>

[1]: https://i.stack.imgur.com/PZ2hj.jpg
[2]: https://i.stack.imgur.com/nqz5v.jpg
英文:

I have a bottom sheet and I want to achieve the following image

如何在 API 等级 21 及以上实现顶部阴影效果的最佳方法?

right now it looks flat like:

如何在 API 等级 21 及以上实现顶部阴影效果的最佳方法?

So how could I add a top shadow on a bottom sheet, that slides. In bottom sheet I have a linear layout for the backdrop for example something like:

    &lt;!--This is the backdrop&#39;s content with a BottomSheetBehaviour applied to it--&gt;
    &lt;LinearLayout
        android:id=&quot;@+id/contentLayout&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:orientation=&quot;vertical&quot;
        app:behavior_peekHeight=&quot;356dp&quot;
        app:layout_behavior=&quot;com.google.android.material.bottomsheet.BottomSheetBehavior&quot;&gt;

        &lt;!--This is the backdrop&#39;s header with a title and icon--&gt;

        &lt;RelativeLayout
            android:layout_width=&quot;match_parent&quot;
            android:background=&quot;@drawable/front_backdrop_top&quot;
            android:layout_height=&quot;90dp&quot;&gt;

        &lt;/RelativeLayout&gt;

        &lt;!--And finally this is the body of the backdrop&#39;s content--&gt;
        &lt;RelativeLayout
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            android:elevation=&quot;8dp&quot;
            app:elevation = &quot;8dp&quot;
            android:background=&quot;@drawable/fron_backdrop_main&quot;
            android:paddingStart=&quot;28dp&quot;&gt;

            &lt;androidx.core.widget.NestedScrollView
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;&gt;

                &lt;LinearLayout
                    android:layout_width=&quot;match_parent&quot;
                    android:layout_height=&quot;match_parent&quot;
                    android:orientation=&quot;vertical&quot;&gt;

                    &lt;androidx.recyclerview.widget.RecyclerView
                        android:id=&quot;@+id/fs_rv_search&quot;
                        android:layout_width=&quot;match_parent&quot;
                        android:layout_height=&quot;match_parent&quot; /&gt;

                &lt;/LinearLayout&gt;

            &lt;/androidx.core.widget.NestedScrollView&gt;

        &lt;/RelativeLayout&gt;

    &lt;/LinearLayout&gt;

huangapple
  • 本文由 发表于 2020年5月29日 15:33:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/62080887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定