其他分享
首页 > 其他分享> > 转换后的动画按钮单击不起作用

转换后的动画按钮单击不起作用

作者:互联网

当我单击一个按钮时,翻译动画开始.然后将按钮放置在翻译动画结束的位置.它工作正常,但是在动画按钮单击后不起作用.
提前致谢

public class ButtonFragment extends Activity  implements OnClickListener{

private Button btn;
private int width;
private Boolean flag = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_button_fragment);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    width = size.x;

    btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    TranslateAnimation animation = null;
    switch (v.getId()) {
    case R.id.btn:

        if(flag ==  true) {             
            animation = new TranslateAnimation(0, width-92 , 0, 0);
            flag=false;
        }
        else{
            animation = new TranslateAnimation(width-92,0 , 0, 0);
            flag = true;
        }

        animation.setDuration(1000);
        animation.setFillAfter(true);
        btn.startAnimation(animation);

        break;

    default:
        break;
    }



  }
           }

代码正确对齐

解决方法:

this page中所述:

Another disadvantage of the view animation system is that it only modified where the View was drawn, and not the actual View itself. For instance, if you animated a button to move across the screen, the button draws correctly, but the actual location where you can click the button does not change, so you have to implement your own logic to handle this.

尝试使用属性动画并阅读上面给出的链接.

标签:animation,android-animation,android
来源: https://codeday.me/bug/20191121/2050203.html