2014-09-24 86 views
1

當我點擊一個按鈕的翻譯動畫開始。然後將按鈕放置在翻譯動畫結束的位置。它工作良好,但動畫按鈕點擊後不工作。提前 感謝翻譯後的動畫按鈕點擊不起作用

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; 
    } 



    } 
      } 

代碼正確對齊做

回答

2

在本頁面給出.. http://developer.android.com/guide/topics/graphics/prop-animation.html

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.

嘗試使用屬性動畫...閱讀上面給出的鏈接。