PopupWindow example

来源:互联网 发布:nginx 读音 编辑:程序博客网 时间:2024/05/21 06:53


LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.popwindow, null);/** * <p> * Create a new popup window which can display the * <tt>contentView</tt>. The dimension of the window must be * passed to this constructor. * </p> * LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.popwindow, null);/** * <p> * Create a new popup window which can display the * <tt>conten * <p> * The popup does not provide any background. This should be * handled by the content view. * </p> *  * @param contentView *            the popup's content * @param width *            the popup's width * @param height *            the popup's height * @param focusable *            true if the popup can be focused, false otherwise */final PopupWindow popupWindow = new PopupWindow(layout, 200, 200,true);  /**     * <p>Change the animation style resource for this popup.</p>     *     * <p>If the popup is showing, calling this method will take effect only     * the next time the popup is shown or through a manual call to one of     * the {@link #update()} methods.</p>     *     * @param animationStyle animation style to use when the popup appears     *      and disappears.  Set to -1 for the default animation, 0 for no     *      animation, or a resource identifier for an explicit animation.     *           * @see #update()     */popupWindow.setAnimationStyle(R.style.PopupAnimation2); /**     * <p>Display the content view in a popup window anchored to the bottom-left     * corner of the anchor view offset by the specified x and y coordinates.     * If there is not enough room on screen to show     * the popup in its entirety, this method tries to find a parent scroll     * view to scroll. If no parent scroll view can be scrolled, the bottom-left     * corner of the popup is pinned at the top left corner of the anchor view.</p>     * <p>If the view later scrolls to move <code>anchor</code> to a different     * location, the popup will be moved correspondingly.</p>     *     * @param anchor the view on which to pin the popup window     *     * @see #dismiss()     */popupWindow.showAsDropDown(button, 100, 150);layout.findViewById(R.id.dismissPopupWindow).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {popupWindow.dismiss();}});}


原创粉丝点击