Android 移动动画,实现刷新式的效果

sweepViewSecond = findViewById(R.id.sweepViewSecond);

实现移动方法,setInterpolator实现加速或者变慢效果:

private void frameAnimation(){
    DisplayMetrics metric = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metric);
    int screen_x = metric.widthPixels;     // 屏幕宽度(像素)

    Animation translateAnimationSecond = new TranslateAnimation(- sweepViewSecond.getWidth(),screen_x+sweepViewSecond.getWidth(),0,0);//平移动画  从0,0,平移到100,100
    translateAnimationSecond.setDuration(1200);//动画持续的时间为1.5s
    translateAnimationSecond.setRepeatMode(Animation.RESTART);
    translateAnimationSecond.setRepeatCount(Integer.MAX_VALUE);
    translateAnimationSecond.setInterpolator(new AccelerateDecelerateInterpolator());
    sweepViewSecond.startAnimation(translateAnimationSecond);
}

xml布局:


    

 

shape.xml :



    

Android 移动动画,实现刷新式的效果_第1张图片

你可能感兴趣的:(android)