android学习——popupWindow 在指定位置上的显示
2014-12-08 12:15
429 查看
popupWindow 在控件的各个方向上的显示(上、下、左、右),主要用到popupWindow 的showAtLocation()方法:
在控件的上方:
[java] view
plaincopy
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_GR***ITY, location[0], location[1]-popupWindow.getHeight());
}
在控件的其他方向上显示只需修改最后一行代码即可,如:
下方:popupWindow.showAsDropDown(v);
左边:
[java] view
plaincopy
popupWindow.showAtLocation(v, Gravity.NO_GR***ITY, location[0]-popupWindow.getWidth(), location[1]);
右边:
[html] view
plaincopy
popupWindow.showAtLocation(v, Gravity.NO_GR***ITY, location[0]+v.getWidth(), location[1]);
在控件的上方:
[java] view
plaincopy
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_GR***ITY, location[0], location[1]-popupWindow.getHeight());
}
在控件的其他方向上显示只需修改最后一行代码即可,如:
下方:popupWindow.showAsDropDown(v);
左边:
[java] view
plaincopy
popupWindow.showAtLocation(v, Gravity.NO_GR***ITY, location[0]-popupWindow.getWidth(), location[1]);
右边:
[html] view
plaincopy
popupWindow.showAtLocation(v, Gravity.NO_GR***ITY, location[0]+v.getWidth(), location[1]);
相关文章推荐
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android学习——popupWindow 在指定位置上的显示
- android 学习之popupWindow 在指定位置上的显示,进出样式。
- android 之popupWindow 在指定位置上的显示
- android popupwindow 位置显示
- Android PopupWindow显示位置设置
- android PopupWindow显示位置设置
- android 之popupWindow 在指定位置上的显示
- popupWindow 指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- 将中心点移动至指定位置,并显示其信息【GMap 学习笔记】
- Android根据屏幕点击位置显示(此处是PopupWindow)
- Android自定义Toast,指定Toast信息显示的位置并使用Toast显示其他View
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示