android中实现PopupWindow跟随ProgressBar进度显示
2017-04-09 13:47
603 查看
早就想写博客了,直到今天才开始真正的去写一篇,接下来奉上今天的主题:实现PopupWindow跟随ProgressBar进度显示
最近遇到一个功能实现,大概就是以下这个图的样子,上方为PopupWindow,下方有ProgressBar,PopupWindow位置跟随ProgressBar进度位置动态变化
开始实现吧:
首先实例化PopupWindow
然后去测量PopupWindow的宽高,因为放置位置为PopupWindow的中央:
因为绘画过程异步,所以使用view的post方法,携带自身宽高属性以供获得,需要注意的是:
若是不设置测量模式,则获取不到PopupWindow的属性(已踩过坑)
另外需要注意的是,如果不做任何操作,这样直接显示PopupWindow,会导致界面的控件获取不到焦点,并且返回键失效(仅针对上图实现的功能来说),所以需要做如下操作:
接下来是对Progress进行操作:
同理,使用view的post方法获得自己的属性,然后首先获取自身的宽高:
然后获得在屏幕中的x,y值:
最后设置popwindow的位置:
上述代码中的percentage为ProgressBar的当前百分比,至于PopupWindow在何处显示,请看管自行百度。
人生第一遍博客,如有错误,请指出,谢谢观看!
最近遇到一个功能实现,大概就是以下这个图的样子,上方为PopupWindow,下方有ProgressBar,PopupWindow位置跟随ProgressBar进度位置动态变化
开始实现吧:
首先实例化PopupWindow
pop_wiew = LayoutInflater.from(this).inflate(R.layout.member_popwindow, null, false);
mPopupWindow = new PopupWindow(pop_wiew, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
然后去测量PopupWindow的宽高,因为放置位置为PopupWindow的中央:
pop_wiew.post(new Runnable() { @Override public void run() { pop_wiew.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popwidth = pop_wiew.getMeasuredWidth(); pophight = pop_wiew.getMeasuredHeight(); } });
因为绘画过程异步,所以使用view的post方法,携带自身宽高属性以供获得,需要注意的是:
pop_wiew.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
若是不设置测量模式,则获取不到PopupWindow的属性(已踩过坑)
另外需要注意的是,如果不做任何操作,这样直接显示PopupWindow,会导致界面的控件获取不到焦点,并且返回键失效(仅针对上图实现的功能来说),所以需要做如下操作:
mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(false); mPopupWindow.setOutsideTouchable(false);
接下来是对Progress进行操作:
mProbarLeftMembercenterExpeience.post(new Runnable() { @Override public void run() { int width = mProbarLeftMembercenterExpeience.getWidth(); int height = mProbarLeftMembercenterExpeience.getHeight(); int[] location = new int[2]; mProbarLeftMembercenterExpeience.getLocationOnScreen(location); //获得在屏幕中的x,y值 int x = location[0]; int y = location[1]; //目前popwindow应该在的x值 int poplocation = (int) (width * baifenbi + x); mPopupWindow.showAtLocation(mProbarLeftMembercenterExpeience, Gravity.NO_GRAVITY, poplocation - popwidth / 2, y - pophight - height); } });
同理,使用view的post方法获得自己的属性,然后首先获取自身的宽高:
int width = mProbarLeftMembercenterExpeience.getWidth(); int height = mProbarLeftMembercenterExpeience.getHeight();
然后获得在屏幕中的x,y值:
int[] location = new int[2]; mProbarLeftMembercenterExpeience.getLocationOnScreen(location); //获得在屏幕中的x,y值 int x = location[0]; int y = location[1];
最后设置popwindow的位置:
int poplocation = (int) (width * percentage+ x); mPopupWindow.showAtLocation(mProbarLeftMembercenterExpeience, Gravity.NO_GRAVITY, poplocation - popwidth / 2, y - pophight - height);
上述代码中的percentage为ProgressBar的当前百分比,至于PopupWindow在何处显示,请看管自行百度。
人生第一遍博客,如有错误,请指出,谢谢观看!
相关文章推荐
- 圆弧矩形进度条,可用于在layout或者imageview外层实现进度的显示(改良android-square-progressbar)
- android progressbar 显示两个进度样式的解决方案
- android通过service实现更新并显示下载进度条,最后自动安装实例
- 自定义View实现Android圆形进度条,支持自定义显示的样式
- 【Android】自定义控件实现带百分比显示进度条,可自定义颜色
- Android基础之——利用popupwindow实现通话过程中的来电归属地小窗体的显示
- android 控件之ProgressBar实现双进度条(通常用于流媒体的缓冲区进度)
- Android入门(15)——使用ProgressBar实现进度条
- Android开发模板------WebView加载时显示ProgressBar进度条
- ProgressBar 实现自定义显示进度值
- Android 自定义圆圈进度并显示百分比例控件(纯代码实现)
- android 纯java代码实现自定义进度条(ProgressBar)
- android之实现ProgressBar进度条组件
- 利用Ajax生成ProgressBar:实现同类大批量数据批量生成Html,并实时显示进度条,可查看处理日志
- android之GridView异步加载图片时显示加载进度ProgressBar
- 【android】自定义ProgressDialog实现暂时隐藏进度值并显示等待状态(附源码下载)
- 【android】解决自定义样式progressbar的进度显示问题
- Android 显示或隐藏标题栏进度条TitleProgressBar
- android ProgressBar 实现自定义进度条
- android自定义View实现图片上传进度显示(仿手机QQ上传效果)