如何动画简单视图从下到上移动?

时间:2015-06-20 10:09:22

标签: android android-animation

我需要实现某种类型的进度条。它应该是简单的视图,无限地从上到下移动。我有这个功能的概念艺术: https://lh6.googleusercontent.com/-Gjj5HSumgYc/VXn_PIRtXrI/AAAAAAAADmU/R9rp3GBDU3c/w445-h791-no/castro_splash.gif

黄色区域应从底部移动到底部。怎么能动画这个?

1 个答案:

答案 0 :(得分:0)

使用此方法:

private void moveViewToScreenCenter( View view )
{
    RelativeLayout root = (RelativeLayout) findViewById( R.id.rootLayout );
    DisplayMetrics dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics( dm );
    int statusBarOffset = dm.heightPixels - root.getMeasuredHeight();

    int originalPos[] = new int[2];
    view.getLocationOnScreen( originalPos );

    int xDest = dm.widthPixels/2;
    xDest -= (view.getMeasuredWidth()/2);
    int yDest = dm.heightPixels - (view.getMeasuredHeight()/2) - statusBarOffset;

    TranslateAnimation anim = new TranslateAnimation( 0, xDest - originalPos[0] , 0, yDest - originalPos[1] );
    anim.setDuration(1000);
    anim.setFillAfter( true );
    view.startAnimation(anim);
}