簡體   English   中英

AnimationListener無法在蜂窩設備上運行

[英]animationlistener not working pre honeycomb devices

我想將動畫應用於視圖,並在動畫通過AnimationListener結束時顯示它。 我的代碼適用於設備4.x,但不適用於2.3.3設備,永遠不會調用onAnimationStart和onAnimationEnd方法。

 final Animation toTopAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.move_up);
 toTopAnimation.setDuration(250);
 toTopAnimation.setFillBefore(true);
 toTopAnimation.setFillAfter(true);

 toTopAnimation.setAnimationListener(new AnimationListener() {
     @Override
     public void onAnimationStart(Animation animation) {
          Log.i("log", "onAnimationStart");
     }
     @Override
     public void onAnimationEnd(Animation animation) {
         Log.i("log", "onAnimationEnd");
         mQuickReturnView.setVisibility (View.VISIBLE);
     }

     @Override
     public void onAnimationRepeat(Animation animation) {
     }
 });

  mQuickReturnView.setAnimation(toTopAnimation);
  mQuickReturnView.startAnimation(toTopAnimation);

你看到什么錯了嗎?

謝謝

我有一個類似的問題,並設法解決了。 我仍然不確定這個問題背后的原因是什么,但是它位於視圖內容以及姜餅處理其繪制方式的周圍。

就我而言,我有一個RelativeLayout ,其中有一些視圖。 僅當在調用動畫之前我在RelativeLayout中更改了子視圖的某些值時,動畫才起作用。 例如,我內部有一個TextView ,所以我將調用setText()方法。 也許您也應該嘗試一下:

// ---
mQuickReturnView.setAnimation(toTopAnimation);
someViewInsidemQuickReturnView.setText(getResources().getString(R.string.some_string));
mQuickReturnView.startAnimation(toTopAnimation);
// ---

setText()方法以某種方式更新視圖,然后動畫可以正常工作。

暫無
暫無

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

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