The pop-up window effect of PopupWindow implemented by Android can be used for prompting information.

Source: Internet
Author: User

The pop-up window effect of PopupWindow implemented by Android can be used for prompting information.

As follows:

PopupWindow is a floating container that can be displayed on the current Activity. The position of PopupWindow can be changed. There are two types of PopupWindow: no offset and no offset; there are two types of reference objects: the relative position of a control (Anchor) and the relative position inside the parent container.

 

The PopupWindow implementation code is as follows:

Create PopupWindow

 

LayoutInflater mLayoutInflater = (LayoutInflater) context. getSystemService (LAYOUT_INFLATER_SERVICE); View contentView = mLayoutInflater. inflate (R. layout. pop, null) // R. layout. pop is the layout file PopupWindow pop = new PopupWindow (contentView, LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); pop. setBackgroundDrawable (new BitmapDrawable (); // specifies the pop of the PopupWindow background. setFocusable (true); // sets the focus of PopupWindow. The created PopupWindow has no focus by default.
Show PopupWindow

 

 

// Relative to a widget (lower left), no offset pop. showAsDropDown (View anchor) // relative to a control, there is an offset, xoff is the offset of the X axis, yoff is the offset of the Y axis pop. showAsDropDown (View anchor, int xoff, int yoff) // where the parent container is located, and gravity is the relative location, for example, Central Gravity. CENTER, Gravity. BOTTOM, Gravity. RIGHT | Gravity. BOTTOM right corner of BOTTOM, and the following two parameters are the offset of the x/y axis. Pop. showAtLocation (View parent, int gravity, int x, int y)
Close PopupWindow
pop.dismiss()


 


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.