android 实践- 2015-09-12
2015-10-09 18:11
513 查看
1: viewpager不能自测高
4000
度的解决方案
--: 在xml中定死高度比如直接定为200dp
-- : 重新自定义viewpage的测算,用子类的高度来重新measure父类的高度
核心代码:
4000
度的解决方案
--: 在xml中定死高度比如直接定为200dp
-- : 重新自定义viewpage的测算,用子类的高度来重新measure父类的高度
核心代码:
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = 0; for(int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int h = child.getMeasuredHeight(); if(h > height) height = h; } heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } /** * Determines the height of this view * * @param measureSpec A measureSpec packed into an int * @param view the base view with already measured height * * @return The height of the view, honoring constraints from measureSpec */ private int measureHeight(int measureSpec, View view) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { // set the height from the base view if available if (view != null) { result = view.getMeasuredHeight(); } if (specMode == MeasureSpec.AT_MOST) { result = Math.min(result, specSize); } } return result; }
相关文章推荐
- android项目混淆打包注意事项
- com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: current time:
- android:inputType参数类型说明
- android制作圆角button
- android 实践-2015/09/09
- Android应用安全防御
- Android应用启动闪黑屏
- Android中调用系统相机、系统相册来获取图片,并裁剪图片。
- 【小知识点总结】android:windowSoftInputMode属性详解 和 按back键直接退出Activity,不关闭软键盘的问题
- android ViewPager OnPageChangeListener滑动事件讲解
- lambda 用法及其在Android Studio 中的配置方法
- Android 5.1 wifi 密码掉电后丢失解决
- Android开发之多级下拉列表菜单实现(仿美团,淘宝等)
- Android VerticalViewPager
- AndroidStudio如何导入github项目
- Android开发环境搭建
- android 代码设置progressBar 颜色
- Android中服务管理相关流程getSystemService
- Android高亮标红指定字段
- [Android] 字体使用dp单位避免设置系统字体大小对排版的影响