Effect
The code is very simple, mainly for the translateanimation class
Public translateanimation (INT fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, float
Fromyvalue, int toytype, float toyvalue) since: API Level 1
Constructor to use when building a translateanimation from code
Parameters
Fromxtype |
Specifies how fromxvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent. |
Fromxvalue |
Change in X coordinate to apply at the start of the animation. This value can either be an absolute number if fromxtype is absolute, or a percentage (where 1.0 is 100%) otherwise. |
Toxtype |
Specifies how toxvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent. |
Toxvalue |
Change in X coordinate to apply at the end of the animation. This value can either be an absolute number if toxtype is absolute, or a percentage (where 1.0 is 100%) otherwise. |
Fromytype |
Specifies how fromyvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent. |
Fromyvalue |
Change in Y coordinate to apply at the start of the animation. This value can either be an absolute number if fromytype is absolute, or a percentage (where 1.0 is 100%) otherwise. |
Toytype |
Specifies how toyvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent. |
Toyvalue |
Change in Y coordinate to apply at the end of the animation. This value can either be an absolute number if toytype is absolute, or a percentage (where 1.0 is 100%) otherwise |
The Code is as follows:
Package COM. lenovo. wufl. translateanimationmenu; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. view. animation. animation; import android. view. animation. translateanimation; import android. widget. button; import android. widget. linearlayout; import android. widget. textview; public class extends activity extends {private textview mmenu; private button mbutton; private translateanimation extends; private translateanimation mhideanimation; private Boolean isshow;/** called when the activity is first created. * // @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); initview (); initanimation ();} private void initview () {mmenu = (textview) findviewbyid (R. id. menu); mbutton = (button) findviewbyid (R. id. button); mbutton. setonclicklistener (this); mmenu. setvisibility (view. gone); isshow = false;} private void initanimation () {// move from self-location-1 times to your original location mshowanimation = new translateanimation (animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self,-1.0f, animation. relative_to_self, 0.0f); mhideanimation = new translateanimation (animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self,-1.0f); mshowanimation. setduration (500); mhideanimation. setduration (500) ;}@ overridepublic void onclick (view v) {If (v. GETID () = R. id. button) {If (isshow) {isshow = false; mmenu. startanimation (mhideanimation); mmenu. setvisibility (view. gone);} else {isshow = true; mmenu. startanimation (mshowanimation); mmenu. setvisibility (view. visible );}}}}
Layout:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/menu" android:layout_width="fill_parent" android:layout_height="68dp" android:background="@android:color/darker_gray" android:gravity="center" android:text="I am a menu" android:textColor="@android:color/background_dark" /> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="show/hide menu" /></RelativeLayout>