【问题标题】:Round a corner of a circular progress bar圆形进度条的一角
【发布时间】:2020-11-01 01:36:03
【问题描述】:

我有这个圆形进度条

我想绕过最后一个拐角,所以看起来像这样

可以这样做吗?

这是我的实际进度条的 XML:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360">
<shape
    android:shape="ring"
    android:innerRadiusRatio="3"
    android:thicknessRatio="9"
    android:useLevel="false">

<gradient
    android:type="sweep"
    android:startColor="@android:color/holo_orange_light"
    android:endColor="@android:color/holo_red_light" />

</shape>

</rotate>

还有我的进度条:

<ProgressBar
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:indeterminateDrawable="@drawable/progress"/>

我已经看到它是如何使用 Horizo​​ntalProgressBar 而不是使用 CircularProgressBar 的,是否可以做到这种效果?是怎么做到的?

我试过了,但是不行https://stackoverflow.com/a/53830379/7271027

【问题讨论】:

    标签: android xml android-progressbar


    【解决方案1】:

    你必须以这样的方式扩展你的可绘制对象:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <rotate android:fromDegrees="270" android:toDegrees="270">
                <shape
                    android:innerRadiusRatio="2.55"
                    android:shape="ring"
                    android:thickness="4dp"
                    android:useLevel="true">
                    <solid android:color="@color/yourcolor" />
                </shape>
            </rotate>
        </item>
        <item android:bottom="261dp">
            <shape
                android:innerRadiusRatio="100000"
                android:shape="ring"
                android:thickness="2dp"
                android:useLevel="false">
                <solid android:color="@color/yourcolor" />
            </shape>
        </item>
        <item>
            <rotate>
                <inset android:insetBottom="261dp">
                    <shape
                        android:innerRadiusRatio="100000"
                        android:shape="ring"
                        android:thickness="2dp"
                        android:useLevel="false">
                        <solid android:color="@color/yourcolor" />
                    </shape>
                </inset>
            </rotate>
        </item>
    </layer-list>
    

    这样,您只需在环上放一个点。当然,您必须微调半径和厚度。

    【讨论】:

      【解决方案2】:

      最后我使用了这个库https://github.com/lopspower/CircularProgressBar 它和我想要的非常相似

      【讨论】:

        猜你喜欢
        • 2016-08-06
        • 2017-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-24
        • 1970-01-01
        相关资源
        最近更新 更多