2012-10-23 55 views
1

我有一個LinearLayout,在我的xml文件中創建,其可見性設置爲Gone。然後我使用動畫展示它,這很好。在動畫之後設置LinearLayout的可見性

我淡出我的LinearLayout使用AlphaAnimation,這工作正常。

我的問題

但問題是,當我使用AnimationListeneronAnimationEnd方法被調用聽動畫,它並沒有我LinearLayout的可見性設置爲GONE,因爲我仍然可以點擊它在裏面,這是我知道他們仍然在那裏。

這是我的xml與我的LinearLayout。

<LinearLayout 
     android:id="@+id/photoOptionBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:alpha="1" 
     android:background="@color/gpsBackground" 
     android:orientation="horizontal" 
     android:visibility="gone"> 

     <ImageButton 
      android:id="@+id/displayShareBtn" 
      style="@android:style/Widget.Holo.Button.Borderless.Small" 
      android:background="@android:color/transparent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal" 
      android:padding="20dp" 
      android:src="@drawable/share" 
      android:contentDescription="Share the picture"/> 

     <ImageButton 
      android:id="@+id/displayDiscardBtn" 
      style="@android:style/Widget.Holo.Button.Borderless.Small" 
      android:background="@android:color/transparent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal" 
      android:padding="20dp" 
      android:src="@drawable/contentdiscard" 
      android:contentDescription="Discard Picture"/> 

    </LinearLayout> 

這是我的淡出方法以及監聽器。

AlphaAnimation alpha = new AlphaAnimation(1.0F, 0.0F); 
    alpha.setDuration(PhotoDisplayFragment.FADE_DURATION); // Make animation instant 
    alpha.setFillAfter(true); // Tell it to persist after the animation ends 
    // And then on your layout 
    final LinearLayout temp = this._photoOptionsBar; 
    alpha.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      // TODO Auto-generated method stub 
      temp.setVisibility(View.GONE); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationStart(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

    }); 
    this._photoOptionsBar.startAnimation(alpha); 

我的問題

如何設置動畫結束後,我LinearLayoutGONE的知名度?

預先感謝

+0

刪除setFillAfter。你選擇的方式是正確的 – Blackbelt

+0

我需要setFillAfter,所以當我想淡入它的阿爾法是0 – StuStirling

+0

只需檢查photoOptionsBar可見性並應用fidein動畫。新的AlphaAnimation(0.0F,1.0F); – Blackbelt

回答

2

的問題與setFillAfter這讓當它完成動畫持續。刪除和所有將按預期工作。如果您需要淡入淡出動畫,請檢查_photoOptionsBar visibilty,如果消失,則應用相反動畫:

new AlphaAnimation(0.0F, 1.0F); 
0
final LinearLayout temp = (LinearLayout) findViewById(R.id.photoOptionBar); 
temp.setVisibility(View.GONE); 
+0

我不能使用findViewByID,因爲我不在活動中我在一個片段中 – StuStirling

相關問題