表格行动画的Android过渡动画

时间:2011-04-13 09:39:38

标签: android animation transition invisible tablerow

我有一个桌面按钮触摸,慢慢淡出并变为隐形。为此,我使用了以下代码。

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

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

在另一种情况下,行必须缓慢下降(就像日落一样)并变得不可见。上述代码有哪些变化或如何安排?

1 个答案:

答案 0 :(得分:2)

你想要一个淡出的动画(慢慢调低alpha)并翻译(向下移动行)。这可以在动画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);
相关问题