android popupwindow 位置显示
2014-07-16 16:54
387 查看
1、在控件的上方:
在控件的其他方向上显示只需修改最后一行代码即可,如:
2、下方:
在下方,其它方法
3、左边:
4、右边:
private void showPopUp(View v) { LinearLayout layout = new LinearLayout(this); layout.setBackgroundColor(Color.GRAY); TextView tv = new TextView(this); tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tv.setText("I'm a pop -----------------------------!"); tv.setTextColor(Color.WHITE); layout.addView(tv); popupWindow = new PopupWindow(layout,120,120); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); int[] location = new int[2]; v.getLocationOnScreen(location); popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight()); }
在控件的其他方向上显示只需修改最后一行代码即可,如:
2、下方:
popupWindow.showAsDropDown(v);
在下方,其它方法
int[] location = new int[2]; v.getLocationOnScreen(location); popupWindow.showAtLocation(v, Gravity.TOP, 0,location[1]+v.getHeight());
3、左边:
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
4、右边:
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
相关文章推荐
- Android根据屏幕点击位置显示(此处是PopupWindow)
- 关于Android popupWindow的位置显示 showAtLocation理解
- Android PopupWindow用法(二)_showAsDropDown 方法显示的位置
- android学习——popupWindow 在指定位置上的显示
- android 虚拟键适配PopupWindow显示位置
- Android,安卓,toolbar,menu显示位置,及样式调整,及使用PopupWindow 实现menu下拉菜单gong
- Popupwindow在Android 7.0以上系统位置显示不对的解决办法
- android popupwindow位置显示
- android学习——popupWindow 在指定位置上的显示
- Android PopupWindow 的显示位置
- Android 6.0+ RecyclerView嵌套在ScrollView显示不全以及Android 7.0+ PopupWindow位置显示不对的问题解决
- android学习——popupWindow 在指定位置上的显示
- android PopupWindow显示位置设置
- Android PopupWindow显示位置和显示大小
- Android PopupWindow 弹框布局要显示在某个空间下面位置
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android PopupWindow显示位置
- Android PopupWindow显示位置设置