Android(Java)

Layout Scale Animation

E.I.T.U 2021. 11. 12. 14:22

scale_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.1"
        android:fromYScale="1.1"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

scale_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="0.9"
        android:fromYScale="0.9"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

OnScaleDown in .java

LinearLayout mainLinear = findViewById(R.id.mainLinear);
Animation mainAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_main_scale_down);
mainAnimation.setDuration(350);
mainAnimation.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        mainLinear.setScaleY(0.91f);
        mainLinear.setScaleX(0.91f);
    }

    @Override
    public void onAnimationEnd(Animation animation) {

    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

OnScaleUp in .java

LinearLayout mainLinear = findViewById(R.id.mainLinear);
Animation mainAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim_main_scale_up);
mainAnimation.setDuration(350);
mainAnimation.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        mainLinear.setScaleY(1f);
        mainLinear.setScaleX(1f);
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        ConstraintLayout backLinear = findViewById(R.id.activity_main);
        backLinear.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});