zoukankan      html  css  js  c++  java
  • android popupwindow位置显示

    1、在控件的上方:

    private void showPopUp(View v) {
                    LinearLayout layout = new LinearLayout(this);
                    layout.setBackgroundColor(Color.GRAY);
                    TextView tv = new TextView(this);
                    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                    tv.setText("I'm a pop -----------------------------!");
                    tv.setTextColor(Color.WHITE);
                    layout.addView(tv);
    
                    popupWindow = new PopupWindow(layout,120,120);
                    
                    popupWindow.setFocusable(true);
                    popupWindow.setOutsideTouchable(true);
                    popupWindow.setBackgroundDrawable(new BitmapDrawable());
                    
                    int[] location = new int[2];
                    v.getLocationOnScreen(location);
                    
                    popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight());
            }

    在控件的其他方向上显示只需修改最后一行代码即可,如:

    popupWindow.showAsDropDown(v);

    在下方,其它方法

    int[] location = new int[2];  
    v.getLocationOnScreen(location);
    popupWindow.showAtLocation(v, Gravity.TOP, 0,location[1]+v.getHeight());

    3、左边:

    popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);

    4、右边:

    popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
  • 相关阅读:
    BZOJ 3677: [Apio2014]连珠线 树形DP
    TweenMax说明
    vs 中快捷实现父类方法
    Box2d b2World的RayCast方法
    cocos2d-js 帧序列动画
    cocos2d-js 显示帧序列图中的一帧
    不同类型刚体接触测试
    FlashDevelop调试Air出错
    php 创建删除数据库
    本地php 连接 MySQL
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4213955.html
Copyright © 2011-2022 走看看