簡體   English   中英

如何在動畫圖像上管理OnClickListener?

[英]how to manage OnClickListener on animated image?

我有一個蜜蜂的動畫圖像。 我設置onClick監聽到imageView ,它的工作,但只能在本機位置imageView ,而不是在它的動畫。 我也嘗試使用onTouchListener ,但結果是一樣的。

ImageView動畫時,如何使onClickonTouchListener起作用?

動畫:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:shareInterpolator="true">
<scale
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:duration="8000"
    android:fromXScale="0.2"
    android:toXScale="1.5"
    android:fromYScale="0.2"
    android:toYScale="1.5"
    android:pivotY="0%"
    android:pivotX="50%"/>
<translate
    android:interpolator="@android:anim/bounce_interpolator"
    android:fillBefore="true"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:duration="2000"
    android:toXDelta="35"
    android:toYDelta="85"/>
<rotate
    android:pivotX="50%"
    android:pivotY="0%"
    android:fromDegrees="360"
    android:toDegrees="0"
    android:duration="6000"
    android:repeatMode="reverse"
    android:repeatCount="infinite"/>

的onClick:

public static void onBTNClick_RidBee(Activity activity){
            bee_icon = (ImageView)activity.findViewById(R.id.bee_icon);
            bee_icon.clearAnimation();
    }
}

onTouchListener:

bee_icon.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.d("myLogs", "clear anim bee");
                    bee_icon.clearAnimation();

            }
            return true;
        }
    });

使用android:fillAter="true" fillAfter控制動畫的結束值在結束后是否仍然存在。 默認情況下,動畫后的視圖狀態與動畫前的狀態相同。 例如:假設,在動畫視圖的x位置為10之前,並且您正在將x轉換為100,在動畫之后,位置仍將是10而不是100.但是如果設置fillAfter="true" ,則在動畫x將為100

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM