zoukankan      html  css  js  c++  java
  • api 25 PopupWindow会占据整个屏幕

    解决方法:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // Android 7.x,PopupWindow高度为match_parent,会出现兼容性问题,需要处理兼容性
    int[] mLocation = new int[2];
    stephenCommonTopTitleView.getTopTitleView().getLocationInWindow(mLocation);
    int offsetY = mLocation[1] + stephenCommonTopTitleView.getTopTitleView().getHeight();
    if (Build.VERSION.SDK_INT >= 25) { // Android 7.1中,PopupWindow高度为 match_parent 时,会占据整个屏幕
    //故而需要在 Android 7.1上再做特殊处理
    WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    int screenHeight = wm.getDefaultDisplay().getHeight();
    centWinShare.setHeight(screenHeight - offsetY); // 重新设置 PopupWindow 的高度
    }
    centWinShare.showAtLocation(stephenCommonTopTitleView.getTopTitleView(), Gravity.NO_GRAVITY, 0, offsetY);
    } else {
    centWinShare.showAsDropDown(stephenCommonTopTitleView.getTopTitleView());
    }

    思路大概是这样
    /*if (Build.VERSION.SDK_INT != 24) {
    //只有24这个版本有问题,好像是源码的问题
    showAsDropDown(view);
    } else {
    //7.0 showAsDropDown没卵子用 得这么写
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
    //showAsDropDown(view, 0, marginTop);
    }*/
  • 相关阅读:
    前端页面实现报警器提示音效果
    Bootstrap相关优质项目学习清单
    Bootstrap相关优质项目学习清单
    [慕课笔记] node+mongodb建站攻略
    基础知识(11)- 异常、断言、日志和调试
    洛谷 P2580 于是他错误的点名开始了
    codevs 4189 字典
    HDU 1251 统计难题
    HDU 1827 Summer Holiday
    HDU 3836 Equivalent Sets
  • 原文地址:https://www.cnblogs.com/dubo-/p/9072767.html
Copyright © 2011-2022 走看看