Make activity animate from top to bottom

前端 未结 4 1601
庸人自扰
庸人自扰 2020-12-04 13:00

I am writing an Android app where I want the activity to appear by animating in from the bottom of the screen to the top. I am able to do this with code from here:

4条回答
  •  日久生厌
    2020-12-04 13:38

    In your main xml file. Add id of the root tag and pass this to function. like

    /** The Constant ANIM_NO. */
    public static final int ANIM_NO = 0;
    
    public static void topToDown(Context context, View target, int type,
            int duration) {
    
        if (type == UtilityAnimations.ANIM_NO) {
            UtilityAnimations.topToDown(context, target, duration);
        } else {
            final Animation animation = 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);
            animation.setDuration(duration != 0 ? duration
                    : UtilityAnimations.DURATION_MEDIAM);
            animation.setInterpolator(UtilityAnimations.getInterpolator(
                    context, type));
            target.startAnimation(animation);
        }
    }
    

提交回复
热议问题