【问题标题】:TextView fade out and disappearTextView 淡出并消失
【发布时间】:2017-01-06 00:32:03
【问题描述】:

我的活动中有一个TextView,我想显示文本,然后在活动开始时淡出并完全隐藏它。

我有一个有线的情况,我的代码有时可以工作(TextView 淡出并消失),但大多数时候它不工作(它无法到达onAnimationEnd 函数)。

这是我的代码:

protected void onResume() {
    fadeOut = new AlphaAnimation( 1.0f , 0.0f ) ;
    fadeOut.setDuration(5000);
    //fadeOut.setFillBefore(true);
    fadeOut.setFillAfter(true);
    //fadeOut.setStartOffset(1000);


    fadeOut.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            Log.d(TAG, "fade out start");
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            Log.d(TAG, "fade out end");

            textRotateHint.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            Log.d(TAG, "fade out repeat");
        }
    });

    textRotateHint.setVisibility(View.VISIBLE);
    textRotateHint.setText(R.string.rotation_hint);
    textRotateHint.startAnimation(fadeOut);

    super.onResume();
}

【问题讨论】:

  • 这可能意味着onResume() 并不总是被调用。
  • 对于我的调试,我可以看到它达到了:Log.d(TAG, "fade out start");但从不去:Log.d(TAG, "fade out end");

标签: android animation textview


【解决方案1】:

您可以使用简单的值动画师。

ValueAnimator valueAnimator = ValueAnimator.ofFloat(1f, 0f);
valueAnimator.setDuration(5000);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        float alpha = (float) animation.getAnimatedValue();
        mTextView.setAlpha(alpha);
    }
});
valueAnimator.start();

【讨论】:

    猜你喜欢
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    相关资源
    最近更新 更多