2014-09-24 2 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.

Попробуйте использовать свойство анимации ... Читать ссылку приведенную выше.

Смежные вопросы