Android development window achieves translucent Effect

Source: Internet
Author: User

From: http://android.tgbus.com/Android/tutorial/201106/357509.shtml

The pop-up popwindow code is as follows, which is messy:

Popupwindow = new popupwindow (menuview, layoutparams. fill_parent,
Layoutparams. fill_parent, true );
Popupwindow. showatlocation (findviewbyid (R. Id. Parent), gravity. Center
| Gravity. Center, 0, 0 );
Popupwindow. setanimationstyle (R. style. popupanimation );
// Use the back key to close the popupwindow. Otherwise, you must call dismiss ();
Colordrawable DW = new colordrawable (-00000 );
Popupwindow. setbackgrounddrawable (DW );
Popupwindow. Update ();

The following are the implementation steps:
1. Background Gray:
Popupwindow = new popupwindow (menuview, layoutparams. fill_parent, layoutparams. fill_parent, true );
The second three parameters must be layoutparams. fill_parent to fill the screen and set the background to Gray.
The whole popupwindow is a gridview, and the picture or something is also used to simulate the UC browser interface project. Thank you.
All the key things are in 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: gravity = "center" Android: layout_height = "fill_parent"
Android: layout_gravity = "center" Android: Background = "# b0000000">
<Linearlayout Android: Orientation = "vertical"
Android: layout_width = "wrap_content" Android: gravity = "center"
Android: layout_height = "wrap_content" Android: layout_gravity = "center"
Android: Background = "@ drawable/downbutton_corner">
<Gridview Android: Id = "@ + ID/gridview" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: numcolumns = "4"
Android: verticalspacing = "5dip" Android: horizontalspacing = "5dip"
Android: stretchmode = "columnwidth" Android: gravity = "center"
Android: layout_gravity = "center"/>
</Linearlayout>
</Linearlayout>

Android: Background = "# b0000000" in the first linearlayout is a full-screen background. Many translucent elements found on the Internet are "# e0000000". I think the color is too deep, "# b0000000" is more appropriate.
The second linearlayout is the background of popupwind. The Android: Background = "@ drawable/downbutton_corner" in it is the key. The border and rounded corner are all defined in it.

2. The border of the popupwindow and the background of the rounded corner. The border of downbutton_corne.xmlpopupwindow and the background of the rounded corner.

<Shape xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Shape = "rectangle">
<Gradient Android: startcolor = "# c0000000" Android: endcolor = "# c0000000"
Android: angle = "90"/> <! -- Background color gradient -->
<Stroke Android: dashwidth = "2dp" Android: dashgap = "2dp"
Android: width = "2dp" Android: color = "# ff00ff00"> </stroke>
<! -- Stroke -->
<Corners Android: bottomrightradius = "5dp"
Android: bottomleftradius = "5dp" Android: topleftradius = "5dp"
Android: toprightradius = "5dp"/> <! -- Set rounded corner -->
</Shape>

<Gradient Android: startcolor = "# c0000000" Android: endcolor = "# c0000000" Android: angle = "90"/> <! -- Background color gradient -->
I set a fixed color "# c0000000 ". Android: angle = "90": this is to set the color gradient direction. From top to bottom, from left to right, it seems that it can only be a multiple of 90, and there are only four directions.
<Stroke> </stroke>, the border is implemented.
Dashwidth refers to the edge width. dashgap refers to the gap between each line (because the edge is composed of many small horizontal lines ).

3. Fade-in and fade-out animation
Popupwindow. setanimationstyle (R. style. popupanimation );
This Code sets the style, and the animation file is introduced in the style file. Below is a simple animation, and there are also a lot of animation tutorials. The fade-out animation exchanges the positions of these parameter values. Android: Duration: This is the duration. In order to make it five seconds.

<Set xmlns: Android = "http://schemas.android.com/apk/res/android">
<Scale Android: fromxscale = "0.6" Android: toxscale = "1.0"
Android: fromyscale = "0.6" Android: toyscale = "1.0" Android: Export Tx = "50%"
Android: Duration = "50%" Android: Duration = "5000"/>
<Alpha Android: interpolator = "@ Android: anim/decelerate_interpolator"
Android: fromalpha = "0.0" Android: toalpha = "1.0" Android: Duration = "5000"/>
</Set>

There is another key issue. After pop-up, the back key is invalid. You must set the event dismiss in pop.

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.