【问题标题】:Android transition animation for table row animation表格行动画的Android过渡动画
【发布时间】:2011-04-13 09:39:38
【问题描述】:

我有一个桌面,按一下按钮,它会慢慢淡出并变得不可见。为此,我使用了以下代码。

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

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

在另一种情况下,该行必须缓慢下降(就像日落一样)并且变得不可见。上面的代码有什么变化或者怎么安排?

【问题讨论】:

    标签: android animation transition invisible tablerow


    【解决方案1】:

    您想要一个淡出(缓慢降低 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      相关资源
      最近更新 更多