日常工作记录:解决7.0系统PopupWindow.showAsDropDown()显示位置不正确问题
2018-04-11 15:56
2106 查看
今天做项目的时候发现,安卓5.0机子的PopupWindow显示位置正确,但放在7.0系统的机子上确错位,经百度了一下发现到解决问题(特此以作记录),废话不说直接重写PopupWindow的showAsDropDown();方法即可,下面贴上方法
阅读更多
package com.shixia.sxhr.widget; import android.content.Context; import android.graphics.Rect; import android.os.Build; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.widget.PopupWindow; /** * Created by Administrator on 2017/11/16. * 解决7.0 popuwindow 显示位置不正确问题 */ public class MyPopupWindow extends PopupWindow { public MyPopupWindow(Context context) { super(context); } public MyPopupWindow(Context context, AttributeSet attrs) { super(context, attrs); } public MyPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public MyPopupWindow() { } public MyPopupWindow(View contentView, int width, int height) { super(contentView, width, height); } @Override public void showAsDropDown(View anchor) { if (Build.VERSION.SDK_INT >= 24) { Rect visibleFrame = new Rect(); anchor.getGlobalVisibleRect(visibleFrame); int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom; setHeight(height); } super.showAsDropDown(anchor); } @Override public void showAsDropDown(View anchorView, int xoff, int yoff) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) { int[] a = new int[2]; anchorView.getLocationInWindow(a); showAtLocation(anchorView, Gravity.NO_GRAVITY, xoff, a[1] + anchorView.getHeight() + yoff); } else { super.showAsDropDown(anchorView, xoff, yoff); } } }
阅读更多
相关文章推荐
- [问题解决]Android7.0上PopupWindow的showAsDropDown位置问题
- 解决android7.0上某些PopuWindow显示位置不正确的问题
- Android7.0上PopupWindow的showAsDropDown位置问题 参数无效
- Android7.0上PopupWindow的showAsDropDown位置问题
- 解决android7.0 popwindow设置showAsDropdown不显示在控件下方的问题
- PopupWindow在Android7.0和7.1系统上显示位置不正确的问题解决
- 解决android 7.0 popwindow的showAsDropDown没有效果问题
- Android7.0 7.1 popupwindow showAsDropDown 显示异常解决办法
- Android7.0上PopupWindow的showAsDropDown位置问题
- 解决android 7.0 popwindow的showAsDropDown没有效果问题
- Android PopupWindow在7.0中弹出位置问题
- PopWindow Android 7.0 位置显示不准确解决办法
- easyui工作使用中的datagrid和ie兼容问题解决记录(二 :多个datagrid在ie下,有的数据会显示,有时不显示)
- PopupWindow的showAsDropDown位置问题 Android7.0
- Android N上Popwindow显示位置不正确问题
- Android7.0上某些PopuWindow出现显示位置不正确问题的解决方法
- 日常工作记录:AlertDialog中的取消、确定按钮显示不到问题
- 使用软引用解决Handler内存泄露和显示Popupwindow、Dialog时提示"Unable to add Window-token is null"的问题
- android popupwindow showAsDropDown offsetx无效的问题
- PopupWindow里显示listview 解决ListView取不到ItemClick事件问题