[英]View.setVisibility(View.INVISIBLE) does not work for animated view
我有一個活動(啟動時)在屏幕上顯示一些coachmark視圖(所有ImageButtons),指示應該如何使用應用程序(某些按鈕的功能,滑動行為等)。 淡出動畫與在某些預定義間隔后觸發的每個視圖相關聯。 這按預期工作。 但是,如果用戶以某種方式與活動交互,我希望這些標記更早消失。 觸發這些操作后,我取消動畫並調用setVisibility(View.INVISIBLE);
在coachmark的意見。 但是,視圖的可見性不會改變。 我已嘗試過其他技術 - 從父項中刪除視圖並將alpha設置為0,這些工作正常,但更改視圖可見性不起作用。
設置coachmark的代碼如下所示:
private void animateCoachmark(int id) {
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
final View view = findViewById(id);
animation.setStartOffset(10000);
animation.setDuration(500);
animation.setAnimationListener(new AnimationListenerBase(null) {
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.INVISIBLE);
}
});
view.startAnimation(animation);
coachmarkViews.add(view);
}
改變可見性的有問題的代碼:
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
}
coachmarkView.setVisibility(View.INVISIBLE);
}
這個問題似乎是,只要動畫與視圖相關聯即使動畫已被取消,也不會改變可見性。 更改我的清理代碼以首先將視圖上的動畫設置為null允許視圖按預期消失。
for (final View coachmarkView : coachmarkViews) {
Animation animation = coachmarkView.getAnimation();
if (animation != null) {
animation.cancel();
coachmarkView.setAnimation(null);
}
coachmarkView.setVisibility(View.INVISIBLE);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.