PopupWindow显示在某个控件上方

来源:互联网 发布:个人展示网站源码 编辑:程序博客网 时间:2024/05/17 02:16

PopupWindow有一个显示在在某个上方的方法,但是没有定义一个在控件下方的方法,不知为何.这里提供一个小思路:

public class PopupOrderPriceDetail extends PopupWindow {    private int popupWidth;    private int popupHeight;    public PopupOrderPriceDetail(Activity context, BusTicket busTicket, int size, boolean isInsurance) {        super(context);        View view = LayoutInflater.from(context).inflate(R.layout.order_price_detail, null);        // 设置可以获得焦点        setFocusable(true);        // 设置弹窗内可点击        setTouchable(true);        // 设置弹窗外可点击        setOutsideTouchable(true);        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);        setAnimationStyle(R.style.popup_animation);        setContentView(view);        //获取自身的长宽高        view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);        popupHeight = view.getMeasuredHeight();        popupWidth = view.getMeasuredWidth();    }    public void showUp(View v) {        //获取需要在其上方显示的控件的位置信息        int[] location = new int[2];        v.getLocationOnScreen(location);        //在控件上方显示        showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);    }}
0 2
原创粉丝点击