android 之popupWindow 在指定位置上的显示
2016-05-27 22:09
639 查看
http://blog.csdn.net/dxj007/article/details/8026691
标签: androidlayout
2012-09-27 22:27 101379人阅读 评论(24) 收藏 举报
分类:
android开发(4)
版权声明:本文为博主原创文章,未经博主允许不得转载。
这篇文章主要介绍了popupWindow 在控件的各个方向上的显示(上、下、左、右),主要用到popupWindow 的showAtLocation()方法:
在控件的上方:
[java] view
plain copy
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);
左边:
[java] view
plain copy
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
右边:
[html] view
plain copy
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
标签: androidlayout
2012-09-27 22:27 101379人阅读 评论(24) 收藏 举报
分类:
android开发(4)
版权声明:本文为博主原创文章,未经博主允许不得转载。
这篇文章主要介绍了popupWindow 在控件的各个方向上的显示(上、下、左、右),主要用到popupWindow 的showAtLocation()方法:
在控件的上方:
[java] view
plain copy
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);
左边:
[java] view
plain copy
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
右边:
[html] view
plain copy
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
相关文章推荐
- Android工程文件导入Jar包和So第三方库
- 关于 git reset 命令几个常用参数的理解
- Android四大组件(1.5)--Activity的跳转与传值
- 安卓初识基本控件_RatingBar
- Handler的消息机制原理
- Android-SlidingMenu
- 初始android studio 的 Gradle Plugin
- 大话Binder机制
- 实习入职第七天:android Mediaplayer各种属性和方法简单介绍
- Android聊天室
- android activity返回键被dialog屏蔽
- Android AsyncTask介绍
- viewpager+fragment来回滑动fragment重新加载的简单解决办法
- android-----解决Bitmap内存溢出的一种方法(图片压缩技术)
- android 命令行签名apk
- Android 4.0及以下版本短信漏洞
- Android 序列化
- Android基于特征码查杀手机病毒
- Android 自定义View (一)
- AndroidStudio的用法详解