0
這是一個非常愚蠢的編譯器錯誤,我想知道是否有一個簡單的方法來抑制它(如與註釋)?使用三元運算符時期望的資源的類型動畫
錯誤發生在setCustomAnimations()
的第二個參數上。錯誤是:Expected resource of type anim
。
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
int exit_animation = current_popup == null ? 0 : current_popup.getExitAnimation();
transaction.setCustomAnimations(fragment.getEnterAnimation(), exit_animation); //ERROR
如果我將三元線展開爲下列任何一種,則錯誤消失。
int exit_animation;
if (current_popup == null)
exit_animation = 0;
else
exit_animation = current_popup.getExitAnimation();
或者:
int exit_animation = 0;
if (current_popup != null)
exit_animation = current_popup.getExitAnimation();
我還沒有試過這個,但是你可以把'@ AnimRes'註釋添加到'exit_animation'嗎?我不知道這是否適用於局部變量。 – CommonsWare
@CommonsWare完美!正是我在找什麼。 – Kacy
如果您有機會,請回答您自己的問題並顯示語法。很高興聽到它的工作! – CommonsWare