Android-Rotate和Expand imageview

时间:2014-09-21 13:25:22

标签: android animation rotation imageview expand

我试图在一定程度上旋转图像视图,同时扩展此图像视图的高度! 到目前为止我的代码是:

public class TongueHandler {
    ImageView tongue;
    RelativeLayout.LayoutParams tongue_params;
    ObjectAnimator rotate_tongue;
    ScaleAnimation scale_tongue;
    AnimationSet as;
    ImageView frog;
    Button btn;


    public TongueHandler(Button btn,ImageView frog,ImageView tongue){
        this.btn=btn;
        this.frog=frog;
        this.tongue=tongue;
    }


    public void Initialize()
    {
        tongue.setBackgroundColor(Color.RED);

        tongue_params=new RelativeLayout.LayoutParams(10,100);
        tongue_params.leftMargin=frog.getLeft()+frog.getWidth()/2;
        tongue_params.topMargin=frog.getTop()+frog.getHeight()/2;
        tongue.setLayoutParams(tongue_params);
        Animate();
    }


    public void Animate()
    {
        as=new AnimationSet(true);
        rotate_tongue=ObjectAnimator.ofFloat(tongue, "rotationX", 90.0f, 90+CalcAngle(frog,btn));
        rotate_tongue.setDuration(1);
        rotate_tongue.start();
        System.out.println("This is Angle: "+CalcAngle(frog,btn));
       /* scale_tongue=new ScaleAnimation(1,1,30,btn.getY(),1,2);
        scale_tongue.setDuration(500); */
       // as.addAnimation(scale_tongue);
        tongue.startAnimation(as);
        as.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
               /* as=new AnimationSet(false);
                rotate_tongue=new RotateAnimation(0,CalcAngle(frog,btn),frog.getWidth()/2,frog.getHeight()/2);
                rotate_tongue.setDuration(1);
                scale_tongue=new ScaleAnimation(30,btn.getY(),2,2,15,0);
                scale_tongue.setDuration(200);
                as.addAnimation(rotate_tongue);
                as.addAnimation(scale_tongue);
                tongue.startAnimation(as);*/
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    public float CalcAngle(View frog,View fly)
    {
        float angle = (float) Math.toDegrees(Math.atan2(frog.getY() - DataBase.FlyY, frog.getX() - DataBase.FlyX));
        if(angle < 0){
            angle += 360;
        }
       /* if (frog.getX()>=DataBase.FlyX)
        {
            angle=-90f-angle;
        }
        else
        {
            angle=-90f+angle;
        }*/
        return angle;
    }

}

问题是图像旋转时根本不起作用,但程度错误(我也想立即做到这一点,即使延迟1毫秒),结果通常不会令人满意 任何帮助真的很感激 谢谢;)

0 个答案:

没有答案