Notice that the menu here is not on the menu that is on the machine, but on the android.view.animation.TranslateAnimation provided by the Android SDK (extends Android.view.animation.Animation) An instance of the class is appended to a menu of animated and hidden effects that are generated on a layout.
Principle: Layout (menu) from the screen (next to the edge of the screen, in fact, not necessarily, depending on the needs of the initial and final state of the dynamic move to the screen (in the outside can be next to the edge, also can be away from the point, this does not matter), so you can achieve the effect of dynamic menu. But due to some of the strange features of animation (the setfill** () function, this one in some of the animation I used to have no idea of the effect), I ignore this thing, so we also need to use the XML properties of Android: Visibility When layout (menu) is displayed, set android:visibility= "visible", and when layout (menu) is hidden, set android:visibility= "Gone", where Android: Visibility can have 3 values, "visible" is visible, "invisible" is invisible but occupies space, "gone" is invisible and does not occupy space (the so-called occupy space, this can write an XML to try it on the understanding).
Use of Class translateanimation: Animation has two definitions, one in Java code and one in XML, which is only defined with code (because I didn't use it for XML definitions). Hey.. )。 Don't say much, look at the code.
Here is Translateanimationmenu.java (I also added a scaleanimation generated animation, friends can follow the SDK and program effects to understand):
Package com. Translateanimation.menu;
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;
public class Translateanimationmenu extends activity {
/** called the activity is a. */
Translateanimation showaction, hideaction;
Animation showaction, hideaction;
LinearLayout menu;
Button button;
Boolean menushowed;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
menu = (linearlayout) Findviewbyid (R.id.menu);
Button = (button) Findviewbyid (R.id.button);
This is translateanimation animation.
Showaction = 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);
This is scaleanimation animation.
Showaction = new Scaleanimation (
1.0f, 1.0f, 0.0f, 1.0f, Animation.relative_to_self, 0.0f, animation.relative_to_self, 0.0f;
Showaction.setduration (500);
This is translateanimation animation.
Hideaction = 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);
This is scaleanimation animation.
Hideaction = new Scaleanimation (
1.0f, 1.0f, 1.0f, 0.0f, Animation.relative_to_self, 0.0f, animation.relative_to_self, 0.0f;
Hideaction.setduration (500);
menushowed = false;
Menu.setvisibility (View.gone);
Button.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
if (menushowed) {
menushowed = false;
Menu.startanimation (hideaction);
Menu.setvisibility (View.gone);
}
else {
Menushowed = true;
Menu.startanimation (showaction);
Menu.setvisibility (view.visible);
}
}
});
}
}
Here is 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"
<textview android:layout_width= "fill_parent"
Android:layout_ height= "Wrap_content" android:text= "@string/hello"/>
<linearlayout android:id= "@+id/menu"
Android: layout_height= "100px" android:layout_width= "fill_parent"
android:layout_alignparenttop= "true" Android: Background= "#ffffff"
<textview android:layout_width= "fill_parent"
android:layout_height= "Fill_" Parent "android:text=" I am a Menu "
android:gravity=" center "/>
</linearlayout>
<button android: Id= "@+id/button" android:layout_width= "fill_parent"
android:layout_height= "Wrap_content" Android:layout_ Alignparentbottom= "true"
android:text= "click to show/hide Menu"/>
</relativelayout>