How to make a dialog slide from bottom to middle of screen in android

后端 未结 8 2533
别跟我提以往
别跟我提以往 2020-11-30 17:10

I want to show a dialog on my activity with animation. My dialog will slide from bottom of activity to middle of activity.

/****Edit****/

I\'m sorry for my q

8条回答
  •  感情败类
    2020-11-30 17:49

    Here is the simplest way to animate dialog when showing

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    
        @Override
        public void onShow(DialogInterface dialogInterface) {
            View view = dialog.getWindow().getDecorView();
            //for enter from left
            //ObjectAnimator.ofFloat(view, "translationX", -view.getWidth(), 0.0f).start(); 
    
            //for enter from bottom
            ObjectAnimator.ofFloat(view, "translationY", view.getHeight(), 0.0f).start();
        }
    
    });
    

    In addition to it, make dialog background full screen and transparent when animating from bottom

    Window window = dialog.getWindow();
    window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawableResource(android.R.color.transparent);
    

提交回复
热议问题