一,activity 布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:minHeight="400dp"
android:minWidth="400dp"
android:src="@drawable/level_list_drawable"/>
</RelativeLayout>
二,@drawable/level_list_drawable 对应资源文件
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent"/>
<item
android:drawable="@drawable/start_one"
android:maxLevel="10"
android:minLevel="1"/>
<item
android:drawable="@drawable/start_two"
android:maxLevel="20"
android:minLevel="11"/>
<item
android:drawable="@drawable/start_three"
android:maxLevel="30"
android:minLevel="21"/>
</level-list>
三,java 代码
public class Main3Activity extends AppCompatActivity {
private ImageView iv;
private Drawable levelListDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
iv = (ImageView)findViewById(R.id.iv);
levelListDrawable = iv.getDrawable();
ValueAnimator valueAnimator = ValueAnimator.ofInt(1,30);
valueAnimator.setDuration(10000);
valueAnimator.addUpdateListener(new
ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator
animation) {
levelListDrawable.setLevel((int)animation.getAnimatedValue());
}});
valueAnimator.start();
}
}