Android7.0上PopupWindow的showAsDropDown位置问题
2017-06-03 11:00
537 查看
自定义PopupWindow
package com.example.zhh.myapplicationdialog;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
/**
* Android7.0上PopupWindow的showAsDropDown位置问题
* 自定义PopupWindow
* 重写showAsDropDown方法
* 注意构造方法的写法
*/
public class MyPopupWindow extends PopupWindow{
Context mContext;
private WindowManager mWindowManager;
public MyPopupWindow(View contentView, int width, int height, boolean focusable) {
super();
if (contentView != null) {
mContext = contentView.getContext();
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
setContentView(contentView);
setWidth(width);
setHeight(height);
setFocusable(focusable);
}
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT == 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
}
package com.example.zhh.myapplicationdialog;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
/**
* Android7.0上PopupWindow的showAsDropDown位置问题
* 自定义PopupWindow
* 重写showAsDropDown方法
* 注意构造方法的写法
*/
public class MyPopupWindow extends PopupWindow{
Context mContext;
private WindowManager mWindowManager;
public MyPopupWindow(View contentView, int width, int height, boolean focusable) {
super();
if (contentView != null) {
mContext = contentView.getContext();
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
setContentView(contentView);
setWidth(width);
setHeight(height);
setFocusable(focusable);
}
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT == 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
}
相关文章推荐
- Android7.0上PopupWindow的showAsDropDown位置问题 参数无效
- Android7.0上PopupWindow的showAsDropDown位置问题
- [问题解决]Android7.0上PopupWindow的showAsDropDown位置问题
- Android7.0版本 PopupWindow.showAsDropDown() 白屏无效问题
- Android7.0 popupWindow显示位置的问题
- android popupwindow showAsDropDown offsetx无效的问题
- Android7.0 7.1 popupwindow showAsDropDown 显示异常解决办法
- 解决android7.0 popwindow设置showAsDropdown不显示在控件下方的问题
- 屏幕旋转时调用PopupWindow update方法更新位置失效的问题及解决方案
- 【Android 非常基础】PopupWindow showAtLocation和showAsDropDown参数分析
- PopupWindow showAtLocation和showAsDropDown参数分析
- Android PopupWindow在7.0中弹出位置问题
- window的showAsDropDown失效的问题
- 【Android 非常基础】PopupWindow showAtLocation和showAsDropDown参数分析
- PopupWindow showAtLocation和showAsDropDown参数分析
- 解决android 7.0 popwindow的showAsDropDown没有效果问题
- Android PopupWindow在7.0中弹出位置问题
- Android编程之PopupWindow隐藏及显示方法示例(showAtLocation,showAsDropDown)
- 解决android 7.0 popwindow的showAsDropDown没有效果问题
- PopupWindow的showAsDropDown位置问题 Android7.0