how to make animation for popup window in android

android popup dialog animation
android popup window
android popup window example
android kotlin popup window
android dialog animation programmatically
popup window with listview android example
how to create custom popup in android
android animation

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 set the animation style for the popup window but the animation does not work? here is my codes:

myanim.xml...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0" 
        android:interpolator="@android:anim/accelerate_interpolator" 
        android:duration="4000"
        android:repeatCount="1"/>
</set>

===============================================

Create the popup window

private PopupWindow showOptions(Context mcon){
    try{ 
        LayoutInflater inflater = (LayoutInflater) mcon.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.options_layout,null);
        layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.myanim));
        PopupWindow optionspu = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        optionspu.setFocusable(true);
        optionspu.showAtLocation(layout, Gravity.TOP, 0, 0);
        optionspu.update(0, 0, LayoutParams.WRAP_CONTENT, (int)(hei/5));
        optionspu.setAnimationStyle(R.anim.myanim);
        return optionspu;
    }
    catch (Exception e){e.printStackTrace();
    return null;}
}

================================================= onClick method... (optionsPopup is global variable of type PopupWindow)

 @Override
public void onClick(View v) {
               switch (v.getId()) { 
        case R.id.options:
                optionsPopup=showOptions(this);
            break;  
}

I think the problem is you have provided only one set of animation style. But actually a PopupWindow requires two animations. One will be used by it when window is shown and other one to hide the window.

This is how you should do it,

1) Create Two Different set of animations.

say, popup_show.xml and popup_hide.xml and add it to your anim folder which you have to create inside res folder.

2) Now inside values folder create a xml called styles.xml and add these animations to it like this,

<style name="Animation">
    <item name="android:windowEnterAnimation">@anim/popup_show</item>
    <item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

3) Now set this style to your PopupWindow animation,

 popup.setAnimationStyle(R.style.Animation);

Now it automatically detects window enter and exit and provides with the required animation.

Android Popup Window Animation Example, setDuration(long duration) This method sets the duration of an animation. Create Animation Xml File Steps. Right click app / res folder. Click New —> Android resource file menu item. Input file name and choose Animator in resource type drop down list.


i am using a popup animation with this code:

// Creating the PopupWindow
       layoutInflater = (LayoutInflater)     getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

       inflatedLayoutView = layoutInflater.inflate(R.layout.packages_popup,null);
     inflatedLayoutView.setAnimation(AnimationUtils.loadAnimation(this, R.animator.popupanim)


    popup_l = new PopupWindow(inflatedLayoutView);

   popup_l.setWidth(FrameLayout.LayoutParams.WRAP_CONTENT);
   popup_l.setHeight(FrameLayout.LayoutParams.WRAP_CONTENT);     
   popup_l.setFocusable(true);
   // Clear the default translucent background
   popup_l.setBackgroundDrawable(new BitmapDrawable());       

   popup_l.showAtLocation(parent, Gravity.CENTER, 0 , 0);   

   popup_l.setOutsideTouchable(false);

located in /res/animator/popupanim.xml (popupanim.xml) the animation code is:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<alpha android:fromAlpha="0.0"
        android:toAlpha="1.0" 
        android:interpolator="@android:anim/accelerate_interpolator" 
        android:duration="500"
        android:repeatCount="0"/>
</set>

Android PopupWindow Example, contains a menu of commands and stays on the screen only until you select one of the commands. It then disappears. But actually a PopupWindow requires two animations. One will be used by it when window is shown and other one to hide the Window. This is how you should do it, 1)Create Two Different set of animations. say, popup_show.xml and popup_hide.xml and add it to your anim folder which you have to create inside res folder.


This might be a bit late but the reason why the animation did not show is because you are showing the popupwindow before you set up your animation.

optionspu.showAtLocation(layout, Gravity.TOP, 0, 0);
optionspu.setAnimationStyle(R.anim.myanim);

Reverse the two lines and you will see the animation:

optionspu.setAnimationStyle(R.anim.myanim);
optionspu.showAtLocation(layout, Gravity.TOP, 0, 0);

Android - Animations, check my blog http://myhexaville.com You can get source code here Android Make Cool Pop Duration: 7:50 Posted: Jan 12, 2017 Conclusion. Now you know how to implement your own dialog with your content and can use it in your projects. In the following lessons we will cover the animation of PopUpWindow and the use of the


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

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false"
    >

  <translate
      android:duration="@integer/dialogplus_animation_default_duration"
      android:fromXDelta="0%"
      android:fromYDelta="100%"
      android:toXDelta="0%"
      android:toYDelta="0%"
      />
</set>

2.slide_out_bottom.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false"
    >

  <translate
      android:duration="@integer/dialogplus_animation_default_duration"
      android:fromXDelta="0%"
      android:fromYDelta="0%"
      android:toXDelta="0%"
      android:toYDelta="100%"
      />
</set>

Style:

<style name="popup_window_animation">
        <item name="android:windowEnterAnimation">@anim/slide_in_bottom</item>
        <item name="android:windowExitAnimation">@anim/slide_out_bottom</item>
    </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;}
    }

What is Pop-Up Window? Webopedia Definition, View contentView;new PopupWindow(contentView, width, height, true) origin: OCNYang/Android-Animation-Set setOnDismissListener(this); if (Build. hey guys, in this tutorial i will show you how to create and design an awesome pop up window using android stuido, please like and subscribe if you want more UI tutorial Thank you Source Code


Android Make Cool Pop Up Animations, Animation_Dialog will give a scale and alpha animation. A window animation style may also be specified in the popup window's style  This feature is not available right now. Please try again later.


android.widget.PopupWindow.setAnimationStyle java code , Create a crossfade animation. Crossfade animations (also known as dissolve) gradually fade out one View or ViewGroup while simultaneously  How to create the pop-up window by using XML and Java in Android studio. we will make the background gradient and has a radius corners. Customize Pop Up Window in Android Studio Tutorial Angga


PopupWindow, In the next lesson, we will also look at the animation of the dialog box and use it in conjunction with the RecyclerView list. To begin, add a dependency to display​  Make a layout for the popup window. Add a layout file to res/layout that defines what the popup window will look like. Inflate and show the popup window. Here is the code for the main activity of our example. Whenever the button is clicked, the popup window is inflated and shown over the activity.