Introduction to the usage properties of Android Showasdropdown

Source: Internet
Author: User

The use of Popupwindow can achieve pop-up effect, in fact, like Alertdialog, is also a dialog box, both are often mixed, but also each has a feature. Here's how to use it.
First Initializes a Popupwindow, specifying the window size parameter.

New NULL ), layoutparams.wrap_content, layoutparams.wrap_content);

You can also write separately:

Layoutinflater mlayoutinflater = (layoutinflater) Getsystemservice (layout_inflater_service); // Custom Layouts ViewGroup Menuview =nulltruenewtrue);

Of course, you can also manually set the Popupwindow size.

Mpop.setcontentview (Menuview); // set include View mpop.setwidth (int  ) mpop.setheight (int )// set PopOver size

Set up an entry animation:

Mpop.setanimationstyle (R.style.animationpreview); // Set Animation style mpop.setoutsidetouchable (true); // here set the display Popuwindow after the click on the outside is valid. If False, then clicking outside of Popuwindow does not turn off Popuwindow. Of course it is obvious that it can only be used under touchable. 

When there is mpop.setfocusable (false), the Popuwindow cannot get the focus, even if the settings set the background is not empty and can not click the outside disappear, only by dismiss () disappear, but the outside view of the event can be triggered, The back key can also be dismiss off smoothly. When set to Popuwindow.setfocusable (true), add the following two lines to set the background code, click the outside and the back button will disappear.

Mpop.setfocusable (TRUE);
Need to smooth Popupwindow Dimiss (i.e. click outside the Popuwindow or back key Popuwindow will disappear); Popupwindow background cannot be empty. The background of the Popuwindow.showasdropdown (v) must be set before the Popuwindow method is displayed, or it is not empty:

0 0); // sets the position of the display Popupwindow at the lower left of the view, X, y for coordinate offsets  0,-+); (as a reference to a view), indicating that the pop-up window is referenced by the parent component, on the left side, offset--. Mpop.setondismisslistenerd (new Popupwindow.ondismisslistener () {})// Set window vanishing event Note: Window.xml is a layout file

Summarize:

1. For Popupwindow view layout, get the layout view through Layoutinflator.

Layoutinflater Inflater = (layoutinflater)

This.anchor.getContext (). Getsystemservice (Context.layout_inflater_service);

View Textentryview = inflater.inflate (R.layout.paopao_alert_dialog, NULL);

2, display position, there are many ways to set the display mode

Pop.showatlocation (Findviewbyid (R.ID.LL2), Gravity.left, 0,-90);

Or

Pop.showasdropdown (View anchor, int xoff, int yoff)

3, into the appearance of the animation

Pop.setanimationstyle (r.style.popupanimation);

4, click outside the Popupwindow area, Popupwindow disappear

This.window = new Popupwindow (Anchor.getcontext ());

This.window.setTouchInterceptor (New Ontouchlistener () {

@Override

public boolean OnTouch (View V, motionevent event) {

if (Event.getaction () ==motionevent.action_outside) {

BetterPopupWindow.this.window.dismiss ();

return true;

}

return false;

}

});

Introduction to the usage properties of Android Showasdropdown

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.