Android top pop-up box

Source: Internet
Author: User

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"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.