2015-06-23 37 views
0

我有4個Framelayouts與2個ImageViews(一個可見,一個不可見)在我的佈局。在第一個ImageView上點擊後,在Framelayout中,旋轉到第二個ImageView。像在這個例子中一樣(http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html)。它工作正常,但有沒有選擇組合兩個或更多ImageViews?所以,如果我點擊第一個圖像(android:id =「@ + id/HotView1」),我的android:id =「@ + id/HotView2」和android:id =「@ + id/WarmView2」旋轉togehter爲一個圖像?加入兩個或多個ImageViews

當然,我可以順序旋轉每個視圖,但由於相機角度的旋轉,這看起來不太好。是否有任何簡單快捷的解決方案?

[...] 
    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" > 

     <ImageView 
      android:id="@+id/HotView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/hot_notactiv" /> 

     <ImageView 
      android:id="@+id/HotView2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/hot_activ" /> 
    </FrameLayout> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <ImageView 
      android:id="@+id/WarmView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/warm_notactiv" /> 

     <ImageView 
      android:id="@+id/WarmView2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/warm_activ" /> 
    </FrameLayout> 
[...] 
+0

添加兩一個線性或相對佈局中的圖像爲整個佈局提供動畫。 – pcj

+0

但它,但它取決於...有時我想結合圖像有時不。我的旋轉方法如下所示:private void applyRotation(float start,float end,ImageView image1,ImageView image2)。所以我需要一個ImageView進行旋轉 – h0ppel

回答

0

嗨,首先給所有你想要動畫的LinearLayout和ImageView提供id。所以你可以參考他們。

然後定義一個函數,將動畫像傳遞的觀點:

public void myAnimation(View viewToAnimate) { 
// Your code for animating which will be comman 
} 

現在同時獲得的LinearLayout和ImageView的的參考,檢查條件,其瀏覽動畫,如:

if(wantToAnimateLinearLayout == true) { 
    myAnimation(linearLayoutReference); 
} else { 
    myAnimation(imageViewReference); 
}