Android-PopupWindow pop-up window

Source: Internet
Author: User

There are two types of Android dialogs: PopupWindow and AlertDialog. Their differences are:
The position of AlertDialog is fixed, while the position of PopupWindow can be random.
AlertDialog is a non-blocking thread, while PopupWindow is a blocking thread.
The position of PopupWindow can be divided into two types: Offset and no offset based on whether there is any offset. According to the difference of the reference object, it can be divided into a control (Anchor) and a parent control. The details are as follows:
ShowAsDropDown (View anchor): relative to a control (lower left), no offset
ShowAsDropDown (View anchor, int xoff, int yoff): The position of a widget with an offset.
ShowAtLocation (View parent, int gravity, int x, int y): The position relative to the parent control (for example, central Gravity. CENTER. Gravity. BOTTOM, etc.), you can set an offset or no offset
Code

[Java]
LayoutInflater inflater = (LayoutInflater) DeliveryActivity. this. getSystemService (LAYOUT_INFLATER_SERVICE );
View view = inflater. inflate (R. layout. popup_sms, null );
 
LinearLayout popup_contact = (LinearLayout) view. findViewById (R. id. popup_contact );
LinearLayout popup_input = (LinearLayout) view. findViewById (R. id. popup_input );
Popup_contact.setOnClickListener (DeliveryActivity. this );
Popup_input.setOnClickListener (DeliveryActivity. this );
 
SelectSMSPopup = new PopupWindow (view );
SelectSMSPopup. setWidth (WindowManager. LayoutParams. WRAP_CONTENT );
SelectSMSPopup. setHeight (WindowManager. LayoutParams. WRAP_CONTENT );
// It must be set. Otherwise, no response is returned when you click elsewhere on the page.
SelectSMSPopup. setBackgroundDrawable (new BitmapDrawable ());
// Set the focus, which must be set; otherwise, the listView cannot respond.
SelectSMSPopup. setFocusable (true );
// Set the position to disappear when you click somewhere else
SelectSMSPopup. setOutsideTouchable (true );
// Display at a certain position
SelectSMSPopup. showAsDropDown (LinearLayout

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.