mimRepaymentProgress.setBackground(ad);
ad.start();
handler.sendEmptyMessageDelayed(100, 1500);
isOverdue = true;
} else {
mtvRepaymentStatement.setText(R.string.home_prepayment);
mllOverdue.setVisibility(View.GONE);
for (int i = 0; i < 15 - productInfo.getData().getOrderDetail().getRepayDay(); i++) {
ad.addFrame(getResources().getDrawable(res.get(i)), 100);
}
ad.setOneShot(true);
mimRepaymentProgress.setBackground(ad);
ad.start();
}
}
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case 100:
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 1, 0.5f, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(100);
animationSet.addAnimation(scaleAnimation);
//启动动画
mllOverdueDay.startAnimation(animationSet);
mllOverdueDay.setVisibility(View.VISIBLE);
break;
}
return false;
}
});
当启动其他Fragment,Activity并未对本界面进行销毁时AnimationDrawable会停止(回到第一张图片),
返回本界面是可以再次ad.start();//启动动画handler.sendEmptyMessageDelayed(100, 1400);//1400整个动画所需时间,(如有多次启动动画的代码需要handler.removeMessages(100);
<ImageSwitcher
android:id="@+id/image_SwitcherTop"
android:layout_width=“match_parent”
android:layout_height=“250dp”
android:layout_centerHorizontal=“true”
android:layout_marginTop=“80dp” />
imgIds = new int[]{R.mipmap.icon_splash_top_1, R.mipmap.icon_splash_top_2,
R.mipmap.icon_splash_top_3};
imageSwitcherTop.setFactory(this);
imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]);
extends BaseActivity implements ViewSwitcher.ViewFactory
@Override
public View makeView() {
return new ImageView(this);
}
左右滑动事件监听(可以添加动画效果)
@Override
public boolean onTouchEvent(MotionEvent event) {
//继承了Activity的onTouchEvent方法,直接监听点击事件
if (event.getAction() == MotionEvent.ACTION_DOWN) {
//当手指按下的时候
downx = event.getX();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
//当手指离开的时候
upx = event.getX();
if(firstTime){
if (downx > upx && currentPosition < imgIds.length - 1) {
currentPosition++;
imageSwitcherTop.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in));
imageSwitcherTop.setOutAnimation(
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
AnimationUtils.loadAnimation(this, R.anim.lift_out));
imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]);
} else if (upx > downx && currentPosition > 0) {