java - Explicit animations for setAnimationStyle(), what are my choices? -
i try out different animation styles popup window using setanimationstyle(), struggling understand documentation.
developer.android.com, says: "animation style use when popup appears , disappears. set -1 default animation, 0 no animation, or resource identifier explicit animation."
it not give examples, or tell me choices of resource available. suspect best animation purposes sliding in right... exist option? these things can select list or have somehow create own?
edit: current code making popup window (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 put following in 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 pw.setanimationstyle(android.r.style.animation_dialog); worked fine, in as dialog appeared standard animation - if swapped line pw.setanimationstyle(r.anim.test); there no animation. have no idea why.
this working example of setanimationstyle()
on end:
res/anim/in.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator"> <translate android:fromydelta="854" android:toydelta="0" android:duration="1000"/> </set>
res/anim/out.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:interpolator="@android:anim/decelerate_interpolator" android:fromydelta="0" android:toydelta="854" android:duration="10000" /> </set>
layout/main.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/layout" > <button android:id="@+id/btn_show" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="show" /> </relativelayout >
layout/popup.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#cccccc" > <button android:id="@+id/btn_dismiss" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="dismiss"/> </linearlayout>
values/styles.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="popupanimation" parent="android:animation" mce_bogus="1"> <item name="android:windowenteranimation">@anim/in</item> <item name="android:windowexitanimation">@anim/out</item> </style> </resources>
values/strings.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">hello world, mainactivity!</string> <string name="app_name">popupwindow</string> </resources>
mainactivity.java :
public class mainactivity extends activity { /** called when activity first created. */ boolean flag =false; popupwindow popupwindow; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); init(); } public void init() { button btn_show = (button) findviewbyid(r.id.btn_show); layoutinflater inflater = layoutinflater.from(this); view layout = inflater.inflate(r.layout.popup, null); popupwindow =new popupwindow(layout, layoutparams.fill_parent, layoutparams.fill_parent); button btn_dismiss = (button) layout.findviewbyid(r.id.btn_dismiss); btn_dismiss.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub openmenu(); } }); btn_show.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub openmenu(); } }); } public void btn_showonclicked() { openmenu(); } public void btn_dismissonclicked() { openmenu(); } public void openmenu() { if (!flag) { popupwindow.setanimationstyle(r.style.popupanimation); popupwindow.showatlocation(findviewbyid(r.id.btn_show), gravity.no_gravity, 0, 0); popupwindow.setfocusable(true); popupwindow.update(); flag =true; } else { popupwindow.dismiss(); popupwindow.setfocusable(false); flag =false; } } }
and in code add anim file style as:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="test" parent="android:animation" mce_bogus="1"> <item name="android:windowenteranimation">@anim/test</item> </style> </resources>
and in code:
pw.setanimationstyle(android.r.style.test);
thanks & happy coding!!!
Comments
Post a Comment