android PopupWindow 自适应宽度
2015-07-04 22:24
411 查看
PopupWindow弹出的菜单随内容的宽度决定,目前找到自认为比较好的办法是,重写ListView的onMeasure()方法。然后就可以实现了,在此mark一下。
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int maxWidth = meathureWidthByChilds() + getPaddingLeft() + getPaddingRight(); super.onMeasure(MeasureSpec.makeMeasureSpec(maxWidth,MeasureSpec.EXACTLY),heightMeasureSpec); } public int meathureWidthByChilds() { int maxWidth = 0; View view = null; for (int i = 0; i < getAdapter().getCount(); i++) { view = getAdapter().getView(i, view, this); view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); if (view.getMeasuredWidth() > maxWidth){ maxWidth = view.getMeasuredWidth(); } } return maxWidth; }
相关文章推荐
- android 通过获得dimens.xml中定义的大小来设置字体的大小
- android 内存优化方法
- Android开发使用MediaRecorder进行录音
- Android 内存管理 &Memory Leak & OOM 分析
- Android的帧动画补间动画,新手复习
- Android获取短信验证码
- 简单的应用Android的轮播图
- AndroidStudio For Mac 快捷键大全
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它) 分类: Android 2015-07-04 21:40 17人阅读 评论(0) 收藏
- Android 单选框的应用(新手篇)
- android四大组件之BroadCastReceiver的开发实例
- Android 4.4 模拟 home键、back键等keyEvent
- Android自定义SwitchButton左右滑动开关按钮控件
- 设计模式之Singleton(单态/单态)
- Android中Thread的使用之Handler机制
- 创建或打开android模拟器时遇到的问题,以及打开后遇到的Failed to install FragmentTest.apk on device 'emulator-5554': timeout
- 菜单 和ActionBar
- android 弧形自定义view
- Android Please ensure that adb is correctly located at问题解决