进度栏阴影仅在填充的零件上 [英] Progress bar shadow only on filled part

查看:86
本文介绍了进度栏阴影仅在填充的零件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android中实现进度条,尝试仅在填充部分的底部获得阴影,就像这样:

Implementing a progress bar in android, trying to get a drop shadow on the bottom part of the filled section only, like this:

API级别为KitKat及以上,但我不介意仅适用于LOLLIPOP及以上的解决方案。
海拔似乎不起作用,卡视图也不起作用。
有任何建议吗?

API level is KitKat and up but i wont mind a solution that applies to LOLLIPOP and up only. Elevation does not seem to work, nor do the card View. any sugesstions?

推荐答案

创建以下xml形状并将其放置为您的progressBar背景。

Create the following xml shape and place it as your progressBar background.

** xml中的10dp假定progressBar的高度为20dp,并且您希望阴影恰好是阴影的一半。

** The 10dp in the xml assumes the progressBar is 20dp in Height and that you want the shadow to be exactly half of it.

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@android:id/background">
            <layer-list>
                <item android:bottom="10dp">
                    <shape android:shape="rectangle">
                        <solid android:color="@color/orange" />
                    </shape>
                </item>
            </layer-list>
        </item>

        <item android:id="@android:id/progress">
            <clip>
                <layer-list>
                    <item>
                        <shape android:shape="rectangle">
                            <solid android:color="@color/green" />
                        </shape>
                    </item>
                    <item android:top="10dp">
                        <shape android:shape="rectangle">
                            <gradient
                                android:angle="90"
                                android:endColor="@color/black"
                                android:startColor="@color/white" />
                        </shape>
                    </item>
                </layer-list>
            </clip>
        </item>
    </layer-list>

这篇关于进度栏阴影仅在填充的零件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆