草庐IT

getMeasuredWidth

全部标签

android - getMeasuredWidth 返回完全错误的值

我必须测量一个View以隔开其他人。我为此使用此代码:ViewGroupview=...;view.setPadding(10,0,10,0);intwrapContent=RelativeLayout.LayoutParams.WRAP_CONTENT;intspecWidth=MeasureSpec.makeMeasureSpec(wrapContent,MeasureSpec.AT_MOST);view.measure(specWidth,specWidth);intquestionWidth=view.getMeasuredWidth();这在Android4.3模拟器上按预期

android - getMeasuredWidth 返回完全错误的值

我必须测量一个View以隔开其他人。我为此使用此代码:ViewGroupview=...;view.setPadding(10,0,10,0);intwrapContent=RelativeLayout.LayoutParams.WRAP_CONTENT;intspecWidth=MeasureSpec.makeMeasureSpec(wrapContent,MeasureSpec.AT_MOST);view.measure(specWidth,specWidth);intquestionWidth=view.getMeasuredWidth();这在Android4.3模拟器上按预期

android - 如果我在 onResume 中调用 getMeasuredWidth() 或 getWidth() 进行布局,它们会返回 0

如果我在onResume中调用getMeasuredWidth()或getWidth()进行布局,它们会返回0。我认为现在还没有绘制该View。另外我认为我需要将getMeasuredWidth()或getWidth()放入在绘制布局并且已知View测量后调用的回调方法中。我应该使用什么android回调方法? 最佳答案 您不能使用width/height/getMeasuredWidth/getMeasuredHeight在View在系统渲染之前(通常来自onCreate/onResume)。对此的简单解决方案是发布Runnabl

android - 如果我在 onResume 中调用 getMeasuredWidth() 或 getWidth() 进行布局,它们会返回 0

如果我在onResume中调用getMeasuredWidth()或getWidth()进行布局,它们会返回0。我认为现在还没有绘制该View。另外我认为我需要将getMeasuredWidth()或getWidth()放入在绘制布局并且已知View测量后调用的回调方法中。我应该使用什么android回调方法? 最佳答案 您不能使用width/height/getMeasuredWidth/getMeasuredHeight在View在系统渲染之前(通常来自onCreate/onResume)。对此的简单解决方案是发布Runnabl

android - getmeasuredheight() 和 getmeasuredwidth() 在 View.measure() 之后返回 0

在使用view.measure()测量具有恒定尺寸的View之后,getMeasuredHeight()getMeasureWidth()返回0。layout_view.xml,扩展以创建View的布局测量尺寸的函数publicvoidmeasureView(Contextcontext){LayoutInflaterinflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);Viewview=inflater.inflate(R.layout.layout_view,null,f

android - Android SDK 中的 getWidth/Height() 和 getMeasuredWidth/Height() 有什么区别?

AndroidDocumentationsaysView有两种尺寸,测量尺寸和图纸尺寸。测量尺寸是在measurepass(onMeasure方法)中计算的尺寸,而绘图尺寸是屏幕上的实际尺寸。特别是,文档说:Thesevaluesmay,butdonothaveto,bedifferentfromthemeasuredwidthandheight.所以,我的问题是:什么会使图纸尺寸与测量尺寸不同?如果onMeasure(int,int)方法尊重布局要求(作为参数widthMeasureSpec和heightMeasureSpec,SDK如何决定View应该有不同的绘图尺寸?此外,And

android - Android SDK 中的 getWidth/Height() 和 getMeasuredWidth/Height() 有什么区别?

AndroidDocumentationsaysView有两种尺寸,测量尺寸和图纸尺寸。测量尺寸是在measurepass(onMeasure方法)中计算的尺寸,而绘图尺寸是屏幕上的实际尺寸。特别是,文档说:Thesevaluesmay,butdonothaveto,bedifferentfromthemeasuredwidthandheight.所以,我的问题是:什么会使图纸尺寸与测量尺寸不同?如果onMeasure(int,int)方法尊重布局要求(作为参数widthMeasureSpec和heightMeasureSpec,SDK如何决定View应该有不同的绘图尺寸?此外,And