public class Mode extends Activity {
private Button b1,b2,b3,b4;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
                setContentView(R.layout.layout2);
b1 = (Button)findViewById(R.id.b1);
                AnimationSet aset = new AnimationSet(true);//创建动画集合
RotateAnimation rAnimation = new                 RotateAnimation(0,360,Animation.RELATIVE_TO_PARENT,0.2f,Animation.RELATIVE_TO_PARENT,0.2f);
rAnimation.setDuration(36000);
aset.addAnimation(rAnimation);
b1.startAnimation(aset);
}
Button能够饶某一点旋转,但是旋转中不在初始位置时点击没有反应。
我想做的是Button能够绕某一点旋转,并且能一直获得点击事件,应该怎么做呢

解决方案 »

  1.   

    tween动画就是这样的,即使你设置了fillAfter,它接受点击事件的位置也是原来的位置,偏移了就取不到点击了。Property Animation就可以,不过这个是3.0之后才有的
      

  2.   

    我想到了一个笨方法:用绝对布局,不断改变空间的坐标public class MainInterface extends Activity {
    Button btn;
    TextView tv;
    int w,h,x,y,n;
    int k = 0;
    AbsoluteLayout.LayoutParams params;

    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout3);
    btn = (Button)findViewById(R.id.button);
    tv = (TextView)findViewById(R.id.tv);
    params = (AbsoluteLayout.LayoutParams)btn.getLayoutParams();
    final int WIDTH =  this.getWindowManager().getDefaultDisplay().getWidth();
    final int HEIGHT = this.getWindowManager().getDefaultDisplay().getHeight();

    /**
     * n为BUTTON转一个周期的次数。设置每100毫秒更新一次,一周期24秒
     * w为Button宽度,设置为1/6屏幕宽度
     * h为Button高度,设置为与宽度相等
     * x为初始时Button坐标的x,后面会改变。FX不变
     * y为初始时Button坐标的y,后面会改变。FY不变
     */

    n=240;                 
    w = WIDTH/6;
    h = w;
    x = WIDTH/2-40;
    y = HEIGHT/2-WIDTH/4;
    final int R = WIDTH/4;
    final int FX = x;
    final int FY = y;
    params.x = x;
    params.y = h;
    btn.setLayoutParams(new AbsoluteLayout.LayoutParams(w,h,x,y)); btn.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
    tv.setText("BUTTON坐标为:x="+String.valueOf(x)+",    y="+String.valueOf(y));
    }
    });

    final Handler myHandler = new Handler(){
    public void handleMessage(Message msg){
    if(msg.what == 0x1){
    float alf = (float) (Math.PI*2*k/n);
    x = FX + (int)(R*(Math.sin(alf)));
    y = FY - (int)(R*(Math.cos(alf)));
    btn.setLayoutParams(new AbsoluteLayout.LayoutParams(w,h,x,y));
    ++k;
    }
    }
    };

    new Timer().schedule(new TimerTask(){
    public void run() {
    Message msg = new Message();
    msg.what = 0x1;
    myHandler.sendMessage(msg);
    }
    }, 0, 100);//设置100毫秒,此时人会觉得画面是连续的

    }
    }能达到要求,但是不是太挫了点
      

  3.   

    其实自定义一个Button,只需要重写里面的getHitRect()方法就可以了,根据旋转的度数改变可点击区域就行了,不用那么麻烦的吧