2011-04-13 62 views
1

我有一個按鈕觸摸的桌子,慢慢地淡出並且變爲隱形。爲此,我使用了下面的代碼。桌面排列動畫的Android過渡動畫

private TableRow topRow = (TableRow) findViewById(R.id.topRow); 
..... 
..... 

topRow.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out)); 
topRow.setVisibility(View.INVISIBLE); 

在另一種情況下,該行必須緩慢下降(就像日落一樣)並變得不可見。上面的代碼有什麼變化,或者如何安排?

回答

2

你想要一個淡出的動畫(慢慢地調低阿爾法)並翻譯(向下移動該行)。這可以在動畫XML資源文件中設置像這樣:

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<translate android:fromYDelta="0" android:toYDelta="50%p" 
     android:duration="@android:integer/config_longAnimTime"/> 
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
     android:duration="@android:integer/config_longAnimTime" /> 
</set> 

然後,您需要打電話給你新的動畫(如您的代碼示例中做的話),但現在你需要的是動畫前可見開始。如果您將動畫xml作爲sunset.xml存儲在/ res/anim /文件夾中,則應通過包含此代碼來實現您想要的內容:

topRow.setVisibility(View.VISIBLE); 
topRow.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sunset)); 
topRow.setVisibility(View.INVISIBLE);