旋转后按钮操作不起作用

时间:2012-03-03 21:02:10

标签: android android-layout android-button

我有一个相对布局,上面有一些按钮,我创建了一个旋转动画来旋转它

但是当我旋转它时按钮的动作不能正常工作,按钮的动作仍然在旋转前保存按钮的旧位置

任何人都可以帮我解决这个问题

    <ImageButton
        android:id="@+id/last20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="75dp"
        android:background="@null"
        android:src="@drawable/last20_selector" 
        android:onClick="last20OnClick"/>

super.onCreate(savedInstanceState);
    setContentView(R.layout.wheel);

    RelativeLayout layout =  (RelativeLayout) findViewById(R.id.wheelLayout);

    RotateAnimation rotateAnim = new RotateAnimation(0, 45,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);

    rotateAnim.setDuration(1000);
    rotateAnim.setRepeatCount(0);
    rotateAnim.setFillAfter(true);
    layout.startAnimation(rotateAnim);
}

public void last20OnClick(View view) {
        System.out.println("last20OnClick");
    }

2 个答案:

答案 0 :(得分:0)

您的代码中的哪个位置设置了OnClickListener? 尝试将监听器放入onCreate方法:

findViewById(R.id.last20).setOnClickListener(new OnClickListener() {

    public abstract void onClick (View v) {
        last20OnClick(v);
    }
});

希望它可以帮到你!

答案 1 :(得分:0)

尝试设置属性:

android:fillAfter="false"
android:fillBefore="false"

或在java中:

rotateAnim.setFillAfter(false);
rotateAnim.setFillBefore(false);

正如question中所述。它帮助了我。 另外,保持动画从-45度旋转到0度。