`

Anim中实现Scale和Alpha操作ImageView

阅读更多
针对这个动画效果的应用,可以了解如下几个知识点:
1.几种动画结合应用到一个ImageView上;
2.将Drawable中的id标识图片转化为Drawable对象
3.xml呈现上述1中功能点;

1.
ScaleAnimation myAnimation_Scale;
AlphaAnimation myAnimation_Alpha;
		
myAnimation_Alpha = new AlphaAnimation(1f, 0.5f);
myAnimation_Alpha.setAnimationListener(listener);
myAnimation_Alpha.setDuration(1000);

myAnimation_Scale = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1f,
	Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 2);
myAnimation_Scale.setAnimationListener(listener);
myAnimation_Scale.setDuration(1000);
myAnimation_Scale.setInterpolator(new AccelerateInterpolator());

AnimationSet aa = new AnimationSet(true);
	     aa.addAnimation(myAnimation_Alpha);
	     aa.addAnimation(myAnimation_Scale);
		// aa.setDuration(1000);

// animation = AnimationUtils.loadAnimation(this, R.anim.alpha_scale);
scaleImage.startAnimation(aa);


2.
Drawable ico = getResources().getDrawable(R.drawable.home);
ImageView scaleImage.setBackgroundDrawable(ico);
	 ico.mutate().setAlpha(80);


3.alpha_scale.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:shareInterpolator="false">
	<alpha android:interpolator="@android:res/anim/accelerate_decelerate_interpolator"
		android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500"
		android:repeatCount="0">
	</alpha>
	<scale android:interpolator="@android:res/anim/accelerate_decelerate_interpolator"
		android:fromXScale="1.0" android:toXScale="5.0" android:fromYScale="1.0"
		android:toYScale="5.0" android:pivotX="50%" android:pivotY="50%"
		android:duration="2000" android:repeatCount="0" android:startOffset="500"></scale>
</set>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics