为什么我的动画创作java代码不';在我的android项目中不工作?

为什么我的动画创作java代码不';在我的android项目中不工作?,java,android,Java,Android,事实上,我的按钮立即变成蓝色,然后我在Toast消息中看到x&y值! 我怎样才能看到改变比例的动画 Button B = (Button) findViewById(R.id.button1); B.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view.setBackgroundColor

事实上,我的按钮立即变成蓝色,然后我在Toast消息中看到x&y值! 我怎样才能看到改变比例的动画

    Button B = (Button) findViewById(R.id.button1);
    B.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            view.setBackgroundColor(Color.RED);
            // I want to create a scale animation for a button on this for loop
            float x , y;
            for(x = (float) 1.0 ,  y = (float) 1.0 ; x < (float) 2.0 && y < (float) 2.0 ; x += (float) 0.1 , y += (float) 0.1){
                view.setScaleX(x);
                view.setScaleY(y);
                Toast.makeText(MainActivity.this, Float.toString(x) + " " + Float.toString(y), 5).show();
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {}
                }, 100);
            }
            view.setBackgroundColor(Color.BLUE);
            view.setScaleX((float)1.0);
            view.setScaleY((float)1.0);
        }
    });
按钮B=(按钮)findViewById(R.id.button1);
B.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
视图.setBackgroundColor(颜色.红色);
//我想为这个for循环上的按钮创建缩放动画
浮动x,y;
对于(x=(浮点)1.0,y=(浮点)1.0;x<(浮点)2.0和&y<(浮点)2.0;x+=(浮点)0.1,y+=(浮点)0.1){
视图。设置刻度x(x);
视图。设置刻度(y);
Toast.makeText(MainActivity.this,Float.toString(x)+“”+Float.toString(y),5.show();
最终处理程序=新处理程序();
handler.postDelayed(新的Runnable(){
@凌驾
public void run(){}
}, 100);
}
视图。setBackgroundColor(颜色。蓝色);
视图。设置刻度((浮动)1.0);
视图.设置比例((浮动)1.0);
}
});

由于前面的

原因,此解决方案不正确

对于动画,您需要使用用于动画的类。 例如,缩放动画如下所示:

ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.5, 1, 0.5);
scaleAnimation.setDuration(3000);
scaleAnimation.setFillAfter(true)
view.startAnimation(scaleAnimation);

您的祝酒词是否说过
x
y
的值大于
1
?是的,祝酒词说值是1,1.2,1.3,1.4。但我认为我的解决方案不是解决这个问题的常用方法。也许是因为我是初学者:-(好吧,太好了!感谢约瑟夫E.和艾尔达·门苏托夫,因为他们的关心:-)