Android 图片上下旋转

来源:互联网 发布:淘宝宝贝图片下载 编辑:程序博客网 时间:2024/04/30 21:11
import android.view.animation.RotateAnimation;import android.widget.ImageView;    /**     * 根据当前的状态来旋转箭头。        传入的两个参数, arrow 为图片,flag 为状态     */    public static void rotateArrow(ImageView arrow, boolean flag) {        float pivotX = arrow.getWidth() / 2f;        float pivotY = arrow.getHeight() / 2f;        float fromDegrees = 0f;        float toDegrees = 0f;        // flagtrue则向上          if (flag) {            fromDegrees = 180f;            toDegrees = 360f;        } else {            fromDegrees = 0f;            toDegrees = 180f;        }        //旋转动画效果   参数值 旋转的开始角度  旋转的结束角度  pivotX x轴伸缩值           RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees,                pivotX, pivotY);        //该方法用于设置动画的持续时间,以毫秒为单位          animation.setDuration(100);        //设置重复次数           //animation.setRepeatCount(int repeatCount);          //动画终止时停留在最后一帧          animation.setFillAfter(true);        //启动动画          arrow.startAnimation(animation);    }
0 0