使用Android 3.0(Honeycomb)中引入的新动画API,创建此类动画非常简单。

View向下滑动一段距离:view.animate().translationY(distance);

您可以稍后将View其滑回原位,如下所示:view.animate().translationY(0);

您还可以轻松组合多个动画。以下动画将View向下滑动其高度并同时淡入其中:// Prepare the View for the animationview.setVisibility(View.VISIBLE);view.setAlpha(0.0f);// Start the animationview.animate()

.translationY(view.getHeight())

.alpha(1.0f)

.setListener(null);

然后,您可以淡出View后退并将其滑回原始位置。我们还设置了一个动画完成后AnimatorListener我们可以设置View背面的可见性GONE:view.animate()

.translationY(0)

.alpha(0.0f)

.setListener(new AnimatorListenerAdapter() {

@Override

public void onAnimationEnd(Animator animation) {

super.onAnimationEnd(animation);

view.setVisibility(View.GONE);

}

});

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐