Android动画使用单选按钮

时间:2014-03-01 06:21:26

标签: android animation

我创建了一个动画,其中我使用一个单选按钮作为对象和矩阵背景。当活动开始时,对象将沿着矩阵中的每个单元格移动。现在我想要点击它时停止对象。我怎样才能做到这一点??

public class MainActivity extends Activity {

RadioButton rad;
Animation animation1;
Context context = this;
Button move;
Handler handler = new Handler();
Runnable handlerTask;

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

    GridView gridview = (GridView) findViewById(R.id.gridView1);
    rad = (RadioButton) findViewById(R.id.radioButton1);
    // move=(Button)findViewById(R.id.button1);
    gridview.setAdapter(new ImageAdapter(this));
    animation1 = AnimationUtils.loadAnimation(this, R.anim.animation);
    // userInputHandler();

    /*
     * move.setOnClickListener(new View.OnClickListener() {
     * 
     * @Override public void onClick(View arg0) { // TODO Auto-generated
     * method stub
     */
    handlerTask = new Runnable() {
        public void run() {
            if (rad.isChecked()) {
                animation1.cancel();
            } else {
                rad.startAnimation(animation1);
            }

        }

    };

    handlerTask.run();
    // }
    // });

}

public void onAnimationEnd(Animation animation) {
    rad.setVisibility(View.VISIBLE);

}

public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub
    rad.setVisibility(View.VISIBLE);
}

public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub
    rad.setVisibility(View.VISIBLE);

}
}

0 个答案:

没有答案