Anim中实现Scale和Alpha操作ImageView

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

1.Java代码
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);

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.Java代码
Drawable ico = getResources().getDrawable(R.drawable.home);
ImageView scaleImage.setBackgroundDrawable(ico);
ico.mutate().setAlpha(80);

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


3.alpha_scale.xml文件:
Java代码
<?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> [/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值