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

<?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() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(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() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Animation animation =
						AnimationUtils.loadAnimation(FrameActivity.this, R.anim.alpha_anim);
						//给iv设置一个图片
						iv.setImageResource(R.drawable.aa);
						//iv开始播放动画
						iv.startAnimation(animation);
			}
		});
		

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值