2012-04-25 87 views
0

我正在設置「菜單展開」動畫。擴展選項爲嵌套在垂直LinearLayout中的2 RelativeLayoutTranslateAnimation適用於周圍的LinearLayout,並使選項從底部擴展。帶嵌套佈局的TranslateAnimation

問題是隻顯示第一個嵌套RelativeLayout。第二隻變得可見而沒有動畫。

下面是所討論的XML佈局,應用動畫的方法和調用。 非常感謝你對你的思念

<LinearLayout 
    android:id="@+id/bmb_navigation_expanded" 
    style="@style/bmb_RelativeLayout" 
    android:layout_above="@id/bmb_bottom_bar" 
    android:orientation="vertical" 
    android:visibility="gone" > 

    <RelativeLayout 
     style="@style/bmb_RelativeLayout"> 

    option 1 stuff 

    </RelativeLayout> 

    <RelativeLayout    
     style="@style/bmb_RelativeLayout"> 

    option 2 stuff 

    </RelativeLayout> 

</LinearLayout> 

法將動畫到的LinearLayout:

public static void setSlideIn(ViewGroup panel, Context ctx) { 

     AnimationSet set = new AnimationSet(false); 

     Animation animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, 
      Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f 
    ); 
     animation.setDuration(200); 
     set.addAnimation(animation); 

     LayoutAnimationController controller = new LayoutAnimationController(set, 0); 
     panel.setLayoutAnimation(controller); 

    } 

這是我所說的動畫:

 layout.setVisibility(View.VISIBLE); 
     setSlideIn(layout, getActivity()); 

回答

1

這裏回答我的問題。 LayoutAnimationController將動畫分發給所有ViewGroup孩子。如果我想將ViewGroup動畫作爲一個單一的實體,我必須做到以下幾點:

panel.setAnimation(set); 
set.start();