Android动画矢量可绘制:运行时更改
使用android.support.design.widget.FloatingActionButton,如果从布局xml而不是从运行时设置,向量动画(旋转和变形)可以完美工作 工作:Android动画矢量可绘制:运行时更改,android,animation,vector,Android,Animation,Vector,使用android.support.design.widget.FloatingActionButton,如果从布局xml而不是从运行时设置,向量动画(旋转和变形)可以完美工作 工作: android:src="@drawable/vector_anim_play_to_stop" 不工作: floatingActionButton.setImageResource(R.drawable.vector_anim_play_to_stop) 从运行时设置时,它不会正确设置动画,它会执行旋转动画
android:src="@drawable/vector_anim_play_to_stop"
不工作:
floatingActionButton.setImageResource(R.drawable.vector_anim_play_to_stop)
从运行时设置时,它不会正确设置动画,它会执行旋转动画,但不会执行变形。这怎么可能
在这两种情况下,我都以以下内容开始动画:
Animatable animatable = (Animatable) floatingActionButton.getDrawable();
animatable.start();
使用static
create()
方法创建您的Animated Vector Drawable
,并调用setImageDrawable()
而不是setImageResource()
使用setImageDrawable
而不是setImageResource
人,这很简单:)谢谢!请将其作为答案添加,以便我可以接受。