1.animation-list
帧布局文件(顺序显示动画和倒序显示动画)(其中oneshot代表着是否只展示一遍,false会不停的循环播发动画)
在drawable中创建animation_list.xml文件
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@mipmap/ic_launcher1" android:duration="150"/>
<item android:drawable="@mipmap/ic_launcher2" android:duration="150"/>
<item android:drawable="@mipmap/ic_launcher3" android:duration="150"/>
<item android:drawable="@mipmap/ic_launcher4" android:duration="150"/>
<item android:drawable="@mipmap/ic_launcher5" android:duration="150"/>
</animation-list>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical" > <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/animation_list"/> <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始动画"/> <Button android:id="@+id/btn_end" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="停止动画"/> </LinearLayout>
Activity:
public class Secondctivity extends AppCompatActivity implements View.OnClickListener { private ImageView imageView; private Button btn_stsart,btn_end; private AnimationDrawable animationDrawable; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_secondctivity); imageView = (ImageView) findViewById(R.id.imageView); btn_stsart = (Button) findViewById(R.id.btn_start); btn_end = (Button) findViewById(R.id.btn_end); btn_stsart.setOnClickListener(this); btn_end.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn_start://开始动画 imageView.setImageResource(R.drawable.animation_list); animationDrawable = (AnimationDrawable) imageView.getDrawable(); animationDrawable.start(); break; case R.id.btn_end://结束动画 animationDrawable = (AnimationDrawable) imageView.getDrawable(); animationDrawable.stop(); break; } } }