Implementation principle of the android top pop-up box: When a menu is to be displayed, the hidden linearlayout is displayed as an animation. When a menu is hidden, the linearlayout is hidden as an animation. It's actually very simple.
Main. xml Code
<? 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">
<TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "@ string/hello"/>
<Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: id = "@ + id/button" android: text = "display/hide menu"/>
-<LinearLayout android: id = "@ + id/menu" android: layout_width = "fill_parent" android: layout_height = "100dp">
<TextView android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: text = "Haha" android: gravity = "center"/>
</LinearLayout>
</LinearLayout>
The hidden linearlayout layout can be freely displayed.
Java code
Package com. cng;
Import android. app. Activity;
Import android. graphics. Color;
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 AndroidexampleActivity extends Activity {
// Display hidden Animation
Animation showaction, hideaction;
// Display hidden operation objects
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 );
Menu. setBackgroundColor (Color. WHITE );
Button = (Button) findViewById (R. id. button );
// Display the 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 );
Showaction. setDuration (500 );
// Hide the 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 );
Hideaction. setDuration (500 );
Menushowed = false;
Menu. setVisibility (View. GONE );
Button. setOnClickListener (new OnClickListener ()
{
@ Override
Public void onClick (View v)
{
If (menushowed)
{
Menushowed = false;
Menu. startAnimation (hideaction );
Menu. setVisibility (View. GONE );
}
Else
{
Menushowed = true;
Menu. startAnimation (showaction );
Menu. setVisibility (View. VISIBLE );
}
}
});
}
}
Author: "color is empty, empty is color"