【问题标题】:How to move a TextView to the bottom of the screen till it's gone?如何将 TextView 移动到屏幕底部直到它消失?
【发布时间】:2015-11-01 03:01:30
【问题描述】:

我需要将 TextView 滚动到底部,直到它通过执行动画(如在 xml 中翻译动画)而消失。我试图创建一个动画文件并在 xml 中使用 translate 属性,但它会做的是它会下降我在 xml 中设置的特定距离。我不知道如何让它翻译到底部,直到它消失并从屏幕上消失。另一件事是,我还想要一个监听器,当 TextView 消失并在动画结束时从屏幕上消失时执行一些操作。

任何建议将不胜感激。谢谢。

【问题讨论】:

    标签: android android-layout android-animation textview translate-animation


    【解决方案1】:

    您可以计算您希望视图行进的距离,但如果您不想精确,则可以使用屏幕高度:

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    

    然后根据需要为视图设置动画,但在最后添加一个监听器来做你想做的事:

    textView.animate().translationY(screenHeight).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                textView.setVisibility(View.GONE);
            }
        });
    

    您仍然需要在侦听器的最后使视图可见性消失,以确保您不再看到它。

    您也可以尝试使用getBottom() 来表示距离。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多