【问题标题】:How to animate text over another View in Android?如何在 Android 中的另一个视图上为文本设置动画?
【发布时间】:2010-10-20 15:19:30
【问题描述】:

我正在尝试在另一个视图之上为“缩小”的一些文本设置动画。我的代码看起来像:

class BoardView extends View {

private TextView animText;

...

private void animText(String text, int color, int xBlocks, int yBlocks) {
    animText.setText(text);
    animText.setTextColor(color);
    animText.setVisibility(View.VISIBLE);
    final int x = BOARD_X_OFFSET + xBlocks * xBlockSize;
    final int y = BOARD_Y_OFFSET + yBlocks * yBlockSize;
    final float SCALE_FROM = (float) 0.25;
    final float SCALE_TO = (float) 5.0;
    ScaleAnimation anim = new ScaleAnimation(SCALE_FROM, SCALE_TO, SCALE_FROM, SCALE_TO, x, y);
    anim.setDuration(500);
    animText.setAnimation(anim);
    this.setAnimation(null);
    startAnimation(anim);
}

}

BoardViewonDraw() 例程中调用animText。然而,我看到的是 board 缩小,而不是文本,尽管上面调用了 setAnimation()

我查看了主要的 android 文档和另一个 example。即使是正确方向的指针也会有所帮助。

【问题讨论】:

    标签: android animation android-animation


    【解决方案1】:

    嗯,很高兴我不是唯一一个很难找到上述非常微妙的错误的人。错误是:

    startAnimation(anim);
    

    在您将其扩展为之前不太明显:

    this.startAnimation(anim);
    

    在这一点上,为什么外部视图(即“this”)和文本一样具有动画效果就很清楚了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      相关资源
      最近更新 更多