当我点击一个按钮时,翻译动画开始。然后按钮放置在翻译动画结束的地方。它工作正常但在动画按钮单击后不起作用。 提前致谢
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.
尝试使用属性动画并阅读上面给出的链接。
关于android - 翻译动画按钮后点击不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26009366/