android - 翻译动画按钮后点击不起作用

标签 android animation android-animation

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

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/

相关文章:

android - 验证移动设备

android - 在 gridview 中显示动画 gif

android - 使用动画动画化列表项

facebook - 通过 Facebook Messenger API 发送时,GIF 不会生成动画

javascript - Three.js 平面几何动画

java - 为什么在两个项目中从左到右对 ImageView 进行动画处理时,我收到不同的结果?

android - 如何用动画交换 ListView 项目?

Android 绘图按钮到带有自定义 View 的 Canvas ?

java - Android:WAITING线程完成执行该方法

android - Robotium waitForFragment