2011-11-05 52 views
0

我需要2個屏幕自定義動畫象下面這樣解釋:Android的 - 佈局動畫不會留在上面

 

      Screen 1         Screen 2 
-----------------------------    ------------------------------ 
|     |   |   |  |      | 
|     |   |   |  |      | 
|     |   |   |  |      | 
|  List 1  | List2 | ---------> | List 3 |  List 4   | 
| (75% width)  |(25% wid)|   |(25%wid)| (75% width)  | 
|     |   |   |  |      | 
|     |   |   |  |      | 
-----------------------------    ------------------------------ 

  • 用戶對一個很長的觸摸列表1中的項目和從左到右的幻燈片。
  • 包含列表1的視圖從左向右移動(直到屏幕結束)並淡入。顯示屏幕2。

我已經把每個列表中LinearLayout和所有LinearLayout s的包含在根LinearLayout。檢測上List1左向右輕掃後,我做這個

 

         AnimationSet set = new AnimationSet(true); 

         Animation animation = new TranslateAnimation(
          Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.75f, 
          Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
         ); 
         animation.setDuration(500); 
         animation.setZAdjustment(Animation.ZORDER_TOP); // Keep the viewgroup on which this animation applies at the top. 
         set.addAnimation(animation); 

         LayoutAnimationController controller = 
          new LayoutAnimationController(set, 0.0f); 

         screenOne_layoutOne.setLayoutAnimation(controller); 
         screenOne_layoutOne.startLayoutAnimation(); 

我能得到的動畫,但不會留在上面的screenOne_layoutOne(含List 1佈局)。動畫低於List2

誰能告訴我問題在哪裏?

在此先感謝。

回答

0

對於那些有興趣的人,我可以通過將兩個屏幕的佈局放在一個佈局文件中並更改佈局/視圖的visibility來解決這個問題。使用的佈局文件是

<LinearLayout android:id="@+id/featured_view_container" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:visibility="visible" > 

    <ListView android:id = "@+id/featured_list" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="2" /> 

    <ImageView android:layout_height = "match_parent" 
     android:layout_width="wrap_content" 
     android:src="@drawable/seperator"/> 

    <LinearLayout android:id = "@+id/categories" 
     android:orientation="vertical" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 

</LinearLayout> 

<!-- Layout for the screen 2--> 
<LinearLayout android:id="@+id/category_view_container" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:visibility="gone" > 

    <LinearLayout android:id = "@+id/subcategories" 
     android:orientation="vertical" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 

    <ImageView android:layout_height = "match_parent" 
     android:layout_width="wrap_content" 
     android:src="@drawable/seperator"/> 

    <ListView android:id = "@+id/subcategory_list" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="2" /> 

</LinearLayout> 

當我申請的列表1(featured_list)動畫(anim),它停留在上面,如果我做

    anim.setZAdjustment(Animation.ZORDER_TOP)