bug -- android 7.0 popwindow显示位置异常情况解决
android 7.0 popwindow显示位置异常,在android7.1官方进行解决了,但是还是要多7.0的bug进行解决,我的解决方案里面通过重写popwindow进行适配:
import android.content.Context; import android.os.Build; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.widget.PopupWindow; /** * 解决7.0 popwindow显示位置的问题 * Created by soyoungboy on 2017/3/16. */ public class FixPopWindow extends PopupWindow { public FixPopWindow() { } public FixPopWindow(View contentView) { super(contentView); } public FixPopWindow(View contentView, int width, int height) { super(contentView, width, height); } public FixPopWindow(View contentView, int width, int height, boolean focusable) { super(contentView, width, height, focusable); } public FixPopWindow(Context context) { super(context); } public FixPopWindow(Context context, AttributeSet attrs) { super(context, attrs); } public FixPopWindow(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public FixPopWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public FixPopWindow(int width, int height) { super(width, height); } @Override public void showAsDropDown(View anchorView) { super.showAsDropDown(anchorView); if (Build.VERSION.SDK_INT == 24) { int[] a = new int[2]; anchorView.getLocationInWindow(a); showAtLocation(anchorView, Gravity.NO_GRAVITY, 0, a[1] + anchorView.getHeight() + 0); } else { super.showAsDropDown(anchorView); } } @Override public void showAsDropDown(View anchorView, int xoff, int yoff) { if (Build.VERSION.SDK_INT == 24) { 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); } } }