0
我有一個非常簡單的動畫:imageview必須一直向上然後向下。起初,我試着用XML:Android:通過代碼生成動畫但不通過xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillAfter="true">
<set
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="-1"
android:repeatMode="reverse">
<translate
android:fromYDelta="0"
android:toYDelta="10"
android:duration="300">
</translate>
</set>
Animation mAnimation= AnimationUtils.loadAnimation(this, R.anim.myanimation);
immagineNemico.startAnimation(mAnimation);
但它沒有工作:我的ImageView沒上去,只能下來。所以,我讀了一問題的回答和我的代碼做動畫:
immagineNemico.setVisibility(View.VISIBLE);
TranslateAnimation mAnimation = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.02f);
mAnimation.setDuration(300);
mAnimation.setRepeatCount(-1);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setInterpolator(new LinearInterpolator());
immagineNemico.setAnimation(mAnimation);
和它的工作。但爲什麼沒有XML動畫的工作?他們幾乎是一樣的!錯誤在哪裏?
檢查日誌如果發生錯誤,請將其粘貼到此處 –
@EliasFazel沒有錯誤 – Curio