动画Android Ring Shape的扫描角度

Leo*_*rey 9 java android android-animation android-layout shapedrawable

尝试为Android Ring Shape设置动画,以产生与所示图像序列类似的效果.

预期的动画

我找到了Shape Drawable类型的戒指.

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="75dp"
android:thickness="25dp"
android:useLevel="false">
Run Code Online (Sandbox Code Playgroud)

随着ArcShape(startAngle,sweepAngle)方法.

ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 360));     
shape.setIntrinsicHeight(100);
shape.setIntrinsicWidth(100);
shape.getPaint().setColor(Color.BLACK);
Run Code Online (Sandbox Code Playgroud)

然而,问题在于无法找到可绘制形状的扫掠角度属性或为ArcShape创建内半径的能力.

我试图制作一个流畅的动画.

D-C*_*d3r 5

旧线程,但我认为它仍然有用。

我设法使用上面的代码获得了类似的行为:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <size
                android:height="56dp"
                android:width="56dp"/>
            <stroke
                android:width="6dp"
                android:color="#FFFFFF"/>
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <size
                android:height="50dp"
                android:width="50dp"/>
            <stroke
                android:width="6dp"
                android:dashGap="140dp"
                android:dashWidth="16dp"
                android:color="#FF0000"/>
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

这里的关键是使用 dashGap 和 dashWidth 值,直到获得所需的图像。


Leo*_*rey 1

有用的材料:Android:寻找具有内半径和外半径的drawArc()方法

使用 PorterDuff Clear 模式,可以“移除”内部,留下甜甜圈形状。然后,您可以通过扩展动画类来重绘来使用弧的扫角。