相关疑难解决方法(0)

Android旋转imageview,我无法在onAnimationEnd()中设置imageview的最终位置

我想在每次点击按钮时将图像视图从30度旋转.

在第一个clic,我可以正确设置动画,但我不能成功更新动画后的imageview位置.当我再次单击按钮时,动画从imageview的原始位置开始,而不是从第一个动画后的最终位置开始.

这是我的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    turnImg = (ImageView) findViewById(R.id.imageViewturnImg );
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.imgTurn);
    // Getting width & height of the given image.
    int w = bmp.getWidth();
    int h = bmp.getHeight();

    turnImg .setImageBitmap(bmp);

    Button buttonok = (Button) findViewById(R.id.buttonok);
    buttonok.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            turn();
        }
    });

}

public void turn()
{
    float degrees = 30; 

    RotateAnimation anim = new RotateAnimation(0, degrees,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(300);
    anim.setFillEnabled(true);

    anim.setFillAfter(true);

    anim.setAnimationListener(new AnimationListener() { …
Run Code Online (Sandbox Code Playgroud)

animation android rotation imageview

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

animation ×1

imageview ×1

rotation ×1