在android中gif的效果和渐变效果

来源:互联网 发布:c语言程序代码大全 编辑:程序博客网 时间:2024/05/23 22:43
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"     android:oneshot="false">   <item android:drawable="@drawable/aa"  android:duration="300"></item>       <item android:drawable="@drawable/bb"  android:duration="300"></item>        <item android:drawable="@drawable/cc"  android:duration="300"></item>         <item android:drawable="@drawable/dd"  android:duration="300"></item>          <item android:drawable="@drawable/ee"  android:duration="300"></item>           <item android:drawable="@drawable/ff"  android:duration="300"></item>    </animation-list>

oneshot是为了设置一次动画 还是多次动画,true就是一次执行后就停止。



下面的代码就是在imageview中写入drawable中的xml,即上面的代码。

setContentView(R.layout.frame);btn = (Button) findViewById(R.id.button1);iv=(ImageView) findViewById(R.id.imageView1);iv.setImageResource(R.drawable.frame_anim);animationDrawable =(AnimationDrawable) iv.getDrawable();btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubif(animationDrawable.isRunning())animationDrawable.stop();animationDrawable.start();}});

渐变效果:


在res下建文件夹 anim,然后在下面建alpha_anim.xml,

<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromAlpha="1"    android:repeatCount="3"    android:repeatMode="restart"    android:toAlpha="0" ></alpha>

setContentView(R.layout.frame);btn = (Button) findViewById(R.id.button1);iv=(ImageView) findViewById(R.id.imageView1);//iv.setImageResource(R.drawable.frame_anim);animationDrawable =(AnimationDrawable) iv.getDrawable();btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubAnimation animation =AnimationUtils.loadAnimation(FrameActivity.this, R.anim.alpha_anim);//给iv设置一个图片iv.setImageResource(R.drawable.aa);//iv开始播放动画iv.startAnimation(animation);}});

1 0
原创粉丝点击