2013-07-19 62 views
2

我的問題說明

在這張截圖的ListView有兩個ListView秒。動畫細胞出的Android

enter image description here

我想達到的目標是,當我觸摸紫色ListView下,接觸的細胞將向上移動,並在藍色ListView的底部的位置停止。

例如,如果我觸摸了「決定心臟移植」,那麼它們將是一個動畫,顯示該細胞向上移動,然後停止在「肝移植」位置。

我曾嘗試

我在紫ListView

@Override 
    public void onListItemClick(ListView l, View v, int position, long id) { 


     // Setup the animation view 

     Log.d("onListItemClick", "Position: " + viewForAnim.getX() + ", " + viewForAnim.getY()); 

     // Move up the selected view 
     Animation animation = null; 

     animation = new TranslateAnimation(0, 0, 0, -v.getY()-l.getY()); 
     animation.setDuration(700); 
     v.startAnimation(animation); 
} 

試過,但,這似乎將在ListView的綁定選定單元格移動,不能移動出來。

認爲動畫紫ListView的電池可能會由藍色ListView的覆蓋,我甚至嘗試用

l.bringToFront(); 

但是,這種沒有任何工作改變ListView控件的Z順序。

,我也想盡了辦法顯示,該SO後

Android -- How to position View off-screen?

它可能會爲動畫視圖工作得很好,但是這並沒有對我的情況下工作。

然後我試着設置android:clipChildren,那對於需要將列表視圖移出來的動畫不起作用。

所以你們可以指點我一個正確的方法如何實現這種動畫效果?

回答

1

嘗試使用relative_to_parent在翻譯動畫

+0

看看API演示源代碼..你會得到這樣的例子.. – shreyas

+0

THX,我只是用'動畫=新TranslateAnimation(Animation.RELATIVE_TO_SELF嘗試,0,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_PARENT,-100);'即使運動設置爲-100,對我來說動畫就是被觸摸的單元格消失,根本沒有動畫。你能指出我應該看看哪個例子嗎? – dumbfingers

+0

在com.example.android.apis.view包中查看layoutanimation類... – shreyas