how to make animation for popup window in android

后端 未结 4 1417
挽巷
挽巷 2020-12-23 19:26

I hava a popup window in my application, its appears when some button clicked I want to set fade in animation to this window, I put the xml file in \"res/anim\" folder and s

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 20:04

    The PopupWindow custom layout is more convenient, and the display position is freedom there is not any restricted. Use Below code and enjoy animation. In this animation use bottom slide in and slide out but you can change only slide in/out animation and animate any where in your app and one thing more according to your animation, you must to change your Gravity ->> BOTTOM, TOP etc.

    anim resource folder:

    1.slide_in_bottom.xml

    
    
    
      
    
    

    2.slide_out_bottom.xml:

    
    
    
      
    
    

    Style:

    
    

    Method:

     private PopupWindow showOptions(Context mcon){
            try{
                LayoutInflater inflater = (LayoutInflater) mcon.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                View layout = inflater.inflate(R.layout.popup_option_documents_type,null);
                PopupWindow optionspu = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                optionspu.setAnimationStyle(R.style.popup_window_animation);
                optionspu.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
                optionspu.setFocusable(true);
                optionspu.setOutsideTouchable(true);
                optionspu.update(0, 0, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                optionspu.showAtLocation(layout, Gravity.BOTTOM, 0, 0);
    
                return optionspu;
            }
            catch (Exception e){e.printStackTrace();
                return null;}
        }
    

提交回复
热议问题