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

后端 未结 8 2541
别跟我提以往
别跟我提以往 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 18:06

    I tried all the answers in here and it don't work for me. I know all that answers are written long time ago. So let me show how I get it to work. I followed this article.

    In short : create res/anim/slide_up.xml

    
        
        
    
    

    then, create res/anim/slide_bottom.xml

    
        
        
    
    

    Then add a style in res/values/styles.xml

    
    

    Now you can set this animation style to your dialog or alertdialog box like below.

    Dialog dialog = new Dialog(this);
    dialog.getWindow().getAttributes().windowAnimations = animationSource;
    

    Or,

    Dialog dialog = new Dialog(this);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.BOTTOM;
    lp.windowAnimations = R.style.DialogAnimation;
    dialog.getWindow().setAttributes(lp);
    

    I showed example only for dialog boxes, but as I said before you can use this method for alert dialog boxes too.

提交回复
热议问题