美文网首页
view 的visible gone动画

view 的visible gone动画

作者: mercuryli | 来源:发表于2019-12-31 10:44 被阅读0次

1、 4.0后使用

   ViewGroup  container = (ViewGroup) findViewById(R.id.container);
   LayoutTransition transition = new LayoutTransition();
   container.setLayoutTransition(transition)

2、 xml 父布局

android:animateLayoutChanges="true"

3、 4.1后子view的动画

LayoutTransition transition = container.getLayoutTransition();
transition.enableTransitionType(LayoutTransition.CHANGING);

4、 给view设置动画 动画结束后设置其可见不可见

 if (view.getVisibility() == View.VISIBLE {
    TranslateAnimation hideAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
    hideAnim.setDuration(300);
    view.startAnimation(hideAnim);
    hideAnim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }
        @Override
        public void onAnimationEnd(Animation animation) {
            view.setVisibility(View.GONE);
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
} else {
    TranslateAnimation showAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    showAnim.setDuration(300);
    view.startAnimation(showAnim);
    view.setVisibility(View.VISIBLE);
}

参考1

相关文章

网友评论

      本文标题:view 的visible gone动画

      本文链接:https://www.haomeiwen.com/subject/bcutnctx.html