Android 设置形状笔划宽度的动画
我有一个圆心透明的圆:Android 设置形状笔划宽度的动画,android,animation,android-5.0-lollipop,geometry,stroke,Android,Animation,Android 5.0 Lollipop,Geometry,Stroke,我有一个圆心透明的圆: <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=
<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只能操作单参数属性。列出了可以使用对象animator设置动画的唯一属性。这可以通过多种方式实现,最简单的方法之一是: 以编程方式创建形状,并使用
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,您可以在和API中探索更多信息,也可以看看,祝您好运