【问题标题】:ImageButton animation not applied to all statesImageButton 动画不适用于所有状态
【发布时间】:2014-09-10 16:05:01
【问题描述】:

我有一个 ImageButton,其图像随设备方向旋转,因此图像/按钮始终是水平的(请注意,旋转是手动处理的,而不是通过活动生命周期处理)。

这一切都很好,除了当用户按下按钮(按下状态)时,90' 旋转暂时丢失。

按钮动画;

<rotate
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="-90"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="200" android:fillAfter="true">
</rotate>

可绘制的图像按钮;

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"
          android:drawable="@drawable/btn_go_back_pressed" />

    <item android:state_enabled="false"
          android:drawable="@drawable/btn_go_back_disabled" />

    <item android:drawable="@drawable/btn_go_back_normal" />

</selector>

加载动画;

AnimationUtils.loadAnimation(mContext, R.anim.button_rotate90);

然后当设备方向改变时;

    case MessageQue.SET_TO_PORTRAIT:
        inPortrait = true;
        for (View ib : buttonsToAnimate) {
            if (ib instanceof TextView) {
                ib.startAnimation(cntPortraitAnim);
            } else {
                ib.startAnimation(btnPortraitAnim);
            }
        }

有没有人知道为什么,更重要的是,如何解决它?

【问题讨论】:

  • 这可能是因为您使用的视图动画不会更新可点击区域。我建议尝试一个属性动画。

标签: android animation imagebutton


【解决方案1】:

优秀的指针 Whitney - 这也解决了我遇到的可见性问题。 以上代码全部替换为;

case MessageQue.SET_TO_LANDSCAPE:
    for (View ib : buttonsToAnimate) ib.animate().rotation(0).setDuration(200);
    break;
case MessageQue.SET_TO_PORTRAIT:
    for (View ib : buttonsToAnimate) ib.animate().rotation(-90).setDuration(200);
    break;

谢谢。

【讨论】:

    猜你喜欢
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多