安卓popupwindow怎么适配
1、这里我直接给大家代码鲷薯恢罢吧!// 将popupWindow显示在anchor下方public void showAsDropDown(PopupWindow popupWindow荑樊综鲶, View anchor) {if (Build.VERSION.SDK_INT < 24) {popupWindow.showAsDropDown(anchor);} else {// 适配 android 7.0int[] location = new int[2];// 获取控件在屏幕的位置anchor.getLocationOnScreen(location);popupWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, 0, location[1] + anchor.getHeight());}}

2、if (Build.VERSION.SDK_INT < 24) {mPopupWindow = new FixedPopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);} else {int[] location = new int[2];

3、// 获取控件在屏幕的位置anchor.getLocationOnScreen(location);int screenHeight = getScreenHeightPixels(context);mPopupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,screenHeight - (location[1] + anchor.getHeight()));}

4、import android.graphics.Rect;import android.os.Build;import android.view.View;import android.widget.PopupWindow;/*** Created by smart on 2018/5/15.*/public class FixedPopupWindow extends PopupWindow {public FixedPopupWindow(View contentView, int width, int height){super(contentView, width, height);

5、public void showA衡痕贤伎sDropDown(View anchor) {if (Build.VERSION.SDK_INT &爿讥旌护gt;= 24) {Rect rect = new Rect();anchor.getGlobalVisibleRect(rect);// 以屏幕 左上角 为参考系的int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom; //屏幕高度减去 anchor 的 bottomsetHeight(h);// 重新设置PopupWindow高度}super.showAsDropDown(anchor);}...}
