Android View 从左边滑出动画 ,以及从左上,左下,右上,右下放大动画。

Posted 人之所以能,是相信能。

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android View 从左边滑出动画 ,以及从左上,左下,右上,右下放大动画。相关的知识,希望对你有一定的参考价值。

1.从左边滑出动画。

ViewTreeObserver vtobanniang = ivBanniang.getViewTreeObserver();
vtobanniang.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ivBanniang.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int width = ivBanniang.getWidth();
float[] x = {-width, 0};
ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(ivBanniang, "translationX", x);
objectAnimatorX.setDuration(500);
objectAnimatorX.start();
}
});

2.从左上,左下,右上,右下放大出场动画。

中心点更改为左下角:
mGenderSelectorLinearLayout.setPivotX(0);
mGenderSelectorLinearLayout.setPivotY(mGenderSelectorLinearLayout.getHeight());

中心点更改为左上角:
mGenderSelectorLinearLayout.setPivotX(0);

mGenderSelectorLinearLayout.setPivotY(0);

 

中心点更改为右上角:

mGenderSelectorLinearLayout.setPivotX(mGenderSelectorLinearLayout.getWidth()); mGenderSelectorLinearLayout.setPivotY(0);

中心点更改为右下角:

mGenderSelectorLinearLayout.setPivotX(mGenderSelectorLinearLayout.getWidth());
mGenderSelectorLinearLayout.setPivotY(mGenderSelectorLinearLayout.getHeight());


动画:

public void showGenderSelectorAnimation() {
    if (mGenderSelectorLinearLayout == null) {return;}
    mGenderSelectorLinearLayout.post(new Runnable() {
        @Override
        public void run() {
            mGenderSelectorLinearLayout.setPivotX(0);
            mGenderSelectorLinearLayout.setPivotY(mGenderSelectorLinearLayout.getHeight());
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleX", 0.0f, 1.05f);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleY", 0.0f, 1.05f);
            AnimatorSet set = new AnimatorSet();
            set.play(scaleX).with(scaleY);
            set.setDuration(330);
            set.start();
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    if (mGenderSelectorLinearLayout == null) {
                        return;
                    }
                    ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleX", 1.05f, 0.98f);
                    ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleY", 1.05f, 0.98f);
                    AnimatorSet set2 = new AnimatorSet();
                    set2.play(scaleX2).with(scaleY2);
                    set2.setDuration(150);
                    set2.start();
                    set2.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            if (mGenderSelectorLinearLayout == null) {
                                return;
                            }
                            ObjectAnimator scaleX3 = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleX", 0.98f, 1.0f);
                            ObjectAnimator scaleY3 = ObjectAnimator.ofFloat(mGenderSelectorLinearLayout, "scaleY", 0.98f, 1.0f);
                            AnimatorSet set3 = new AnimatorSet();
                            set3.play(scaleX3).with(scaleY3);
                            set3.setDuration(300);
                            set3.start();
                        }
                    });
                }
            });
        }
    });
}

 

以上是关于Android View 从左边滑出动画 ,以及从左上,左下,右上,右下放大动画。的主要内容,如果未能解决你的问题,请参考以下文章

CSS滑入和滑出动画溢出问题

Android开发 从底部弹出动画(选择菜单)

Android Activity 淡入淡出和从底部向上弹出动画效果

如何显示 imageview 滑出动画及其下方的另一个 imageview?

Angular (4, 5, 6, 7) - ngIf 上滑入滑出动画的简单示例

如何从屏幕底部向上滑出一个view-Android开发问答