Android(安卓)View预估大小
16lz
2021-12-04
android的布局分两个阶段,先measure()后requestLayout(),
测量的三种模式:
LinearLayout 调用measure(EXACTLY 240,UNSPECIFIED)来得到高度。
View.measure(widthMeasureSpec,heightMeasureSpec),需要的两个spec是Mode和限定值计算出来的:
View.MeasureSpec.makeMeasureSpec(maxW,View.MeasureSpec.AT_MOST)
measure()后调用getMeasuredWidth()和getMeasuredHeight()得到测量后的值。
此法可用于Tip等窗口大小预估。
参考:
http://code.google.com/android/samples/ApiDemos/src/com/google/android/samples/view/LabelView.html
测量的三种模式:
- UNSPECIFIED: 不限定
- EXACTLY: 固定
- AT_MOST:最多
LinearLayout 调用measure(EXACTLY 240,UNSPECIFIED)来得到高度。
View.measure(widthMeasureSpec,heightMeasureSpec),需要的两个spec是Mode和限定值计算出来的:
View.MeasureSpec.makeMeasureSpec(maxW,View.MeasureSpec.AT_MOST)
measure()后调用getMeasuredWidth()和getMeasuredHeight()得到测量后的值。
此法可用于Tip等窗口大小预估。
参考:
http://code.google.com/android/samples/ApiDemos/src/com/google/android/samples/view/LabelView.html
更多相关文章
- android横竖屏切换不重启activity
- Android(安卓)webview与js交互
- Android中文API(139) —— SQLiteOpenHelper
- java.lang.ClassCastException: android.app.Application cannot
- popwindow动画显示消失,activity切换动画
- android 中调用接口发送短信
- android 中调用接口发送短信
- android调用市场给软件加评论
- Android(安卓)Java与C++的调用