android - 旋转后按钮 Action 不起作用

标签 android android-layout android-button

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

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

谁能帮我解决这个问题

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

最佳答案

尝试设置属性:

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

或者在java中:

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

如本 question 中所建议.它帮助了我。 另外,为了保持您的动画从 -45 度旋转到 0 度。

关于android - 旋转后按钮 Action 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9549844/

相关文章:

java - 对外部 Activity 的 Intent 拒绝许可

android - 单击 TextView 时如何制作动画?

以编程方式进行Android约束布局?

android - 在 galaxy s2 上翻译后布局闪烁

android - 使用 Android Studio 生成 Google Endpoints 库 (JDO)

android - Activity 到 Activity 的交流

android - 删除按钮 View 中的文本填充

android - 如何将 alpha 蒙版应用于 Android 可绘制对象?

c# - Array Adapter 重载方法

android - 带有复选框、单选按钮、 TextView 和按钮的 ListView 在 android 中无法正常工作