android 之popupWindow 在指定位置上的显示
来源:互联网 发布:如何看spring源码 编辑:程序博客网 时间:2024/05/22 19:06
转载地址:http://blog.csdn.net/dxj007/article/details/8026691
这篇文章主要介绍了popupWindow 在控件的各个方向上的显示(上、下、左、右),主要用到popupWindow 的showAtLocation()方法:
在控件的上方:
- 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());
- }
在控件的其他方向上显示只需修改最后一行代码即可,如:
下方:popupWindow.showAsDropDown(v);
左边:
- popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
- popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
0 0
- 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 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- Android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- c++里面的switch-case问题
- 被 7 整除的数
- 第一章 事件与概率
- PHP源码安装出现virtual memory exhausted: Cannot allocate memory
- 如何根据标注图中的px确定dp
- android 之popupWindow 在指定位置上的显示
- C++各大有名库的介绍
- 基于语义依存关系的相似度算法简述
- Android 隐藏程序的图标并使用其他APP启动
- mysql字符串连接和批量插入数据
- 1.0、Android Studio管理你的项目
- ArcGIS教程:将支持页面插入地图册
- PHP TRAIT
- Tor学习