Android 微信摇一摇动画效果

jopen 5年前

两张图片相对平移滑动,

public void startAnim() { // 定义摇一摇动画动画    AnimationSet animup = new AnimationSet(true);    TranslateAnimation  mup0 = new TranslateAnimation(    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,    -0.5f);     mup0.setDuration(1000);    TranslateAnimation  mup1 = new TranslateAnimation(    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,    +0.5f);     mup1.setDuration(1000);    //延迟执行1秒     mup1.setStartOffset(1000);    animup.addAnimation( mup0);    animup.addAnimation( mup1);    //上图片的动画效果的添加    mImgUp.startAnimation(animup);    AnimationSet animdn = new AnimationSet(true);    TranslateAnimation  mdn0 = new TranslateAnimation(    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,    +0.5f);     mdn0.setDuration(1000);    TranslateAnimation  mdn1 = new TranslateAnimation(    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,    -0.5f);     mdn1.setDuration(1000);    //延迟执行1秒     mdn1.setStartOffset(1000);    animdn.addAnimation( mdn0);    animdn.addAnimation( mdn1);    //下图片动画效果的添加    mImgDn.startAnimation(animdn);    }