I would like to try out different animation styles for a popup window using setAnimationStyle(), but I am struggling to understand the documentation.
developer.android.com, says: “animation style to use when the popup appears and disappears. Set to -1 for the default animation, 0 for no animation, or a resource identifier for an explicit animation.”
It does not give any examples, or tell me what choices of resource are available. I suspect the best animation for my purposes will be sliding in from the right… does that exist as an option? Are these things I can select from a list or do I have to somehow create my own?
EDIT: My current code for making my popup window is something like this (simplified):
public void completed_dialog()
{
runOnUiThread(new Runnable()
{
public void run()
{
View layout = inflater.inflate(R.layout.endofgame, null, false);
Button b1 = (Button) layout.findViewById(R.id.pu_menu);
Button b2 = (Button) layout.findViewById(R.id.pu_repeat);
Button b3 = (Button) layout.findViewById(R.id.pu_next);
b1.setBackgroundResource(R.drawable.custom_menu_but);
b2.setBackgroundResource(R.drawable.custom_repeat_but);
b3.setBackgroundResource(R.drawable.custom_next_but);
b1.setOnClickListener(menu_button_click_listener);
b2.setOnClickListener(repeat_button_click_listener);
b3.setOnClickListener(next_button_click_listener);
final PopupWindow pw = new PopupWindow(layout, canvas_width,
canvas_width /2, true);
pw.setAnimationStyle(android.R.style.Animation_Dialog);
pw.showAtLocation(game_frame_layout, Gravity.CENTER, 0, 0);
}
}
}
I have now put the following in a file res/anim/test.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="0%" android:pivotY="0%"
android:duration="@android:integer/config_shortAnimTime"
/>
<alpha
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_shortAnimTime"
/>
</set>
The original code with pw.setAnimationStyle(android.R.style.Animation_Dialog); worked fine, in as much as the dialog appeared with the standard animation – but if I swapped that line with pw.setAnimationStyle(R.anim.test); there is no animation. I have no idea why.
this is working example of
setAnimationStyle()on my end:res/anim/in.xml:
res/anim/out.xml:
layout/main.xml:
layout/popup.xml:
values/styles.xml:
values/strings.xml:
MainActivity.java :
and in your code just add your anim file to style as:
and in code:
Thanks & Happy Coding!!!