gpt4 book ai didi

android - 为形状的笔触宽度设置动画

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:59 26 4
gpt4 key购买 nike

我有一个带有透明中心的粗圆:

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@android:color/transparent"/>
<stroke
android:width="24dp"
android:color="@android:color/white"/>
<size
android:width="72dp"
android:height="72dp"/>
</shape>

并希望为笔画值的减少设置动画,以便透明中心扩张,就像虹膜一样。

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="????"
android:valueFrom="24dp"
android:valueTo="4dp"
android:duration="750"
/>
</set>

...但我不知道要指定什么作为属性名称。 “strokeWidth”似乎不起作用。我什至不确定如何以编程方式实现它,因为 GradientDrawable.setStroke() 需要宽度和颜色,而 objectAnimator 只能操作单个参数属性。

最佳答案

列出了您可以使用对象动画器设置动画的唯一属性 here .这可以通过许多方式完成,最简单的方式之一如下:

以编程方式创建您的 Shape 并使用 ValueAnimator 设置值。您创建了一个 float 的 ValueAnimator 并添加了一个 UpdateListener,因此在每个刻度中,您都可以编辑笔划大小。我会给你一个例子:

例子:

final ShapeDrawable circle = new ShapeDrawable(new OvalShape());

//Create your shape programatically
ValueAnimator animation = ValueAnimator.ofFloat(24.0f,12.0f);
animation.setDuration(1000);
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
circle.getPaint().setStrokeWidth((Float)animation.getAnimatedValue());
}
});

该示例将在一秒钟内将笔划宽度从 24 更改为 12,您可以在 ValueAnimator 中探索更多信息。和 ShapeDrawable api,也看看here , 祝你好运。

关于android - 为形状的笔触宽度设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29265574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com