本文介绍了什么时候调用View.onMeasure()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 什么时候View.onMeasure(int widthMeasureSpec, int heightMeasureSpec)被叫?我有活动,需要在 onMeasure 已被调用。called? I have an Activity that needs to perform an action after onMeasure has been called.我的问题与此处发布的未回答的问题。 查看文档说明 onMeasure .android.com / reference / android / view / View.html#requestLayout%28%29rel =nofollow noreferrer> requestLayout()被调用,当它相信时,它本身就被一个视图调用那不能再适合当前的界限了。My question is the same as the unanswered question posted here. The View documentation states that onMeasure is called when requestLayout() is called, which is apparently called by a view on itself when it believes that is can no longer fit within its current bounds.然而,这并没有告诉我什么时候我的活动可以假设我的查看已经过测量。我已经使用此代码来扩展 ImageView 形成TouchImageView。 这里有人建议我应该使用 onMeasure 方法来缩放我的图像。我希望在 TextView 的价值=http://developer.android.com/reference/android/widget/ImageView.html\"rel =nofollow noreferrer> ImageView 已经过测量,以显示图像缩放的百分比。However, this doesn't tell me when my activity can assume that my View has been measured. I've used this code to extend ImageView to form TouchImageView. It was suggested here that I should use the onMeasure method to scale my image. I wish to update the value of a TextView after the ImageView has been measured in order to display the percentage by which the image has been scaled.推荐答案当父View需要计算布局时,会调用onMeasure。通常,onMeasure可能会被调用多次,具体取决于不同的孩子及其布局参数。onMeasure is called when the parent View needs to calculate the layout. Typically, onMeasure may be called several times depending on the different children present and their layout parameters. onMeasure 被调用(我认为)创建自己的控件,扩展 ImageView 并覆盖onMeasure(只需调用super.onMeasure并执行其他操作)你想这样做。The best way to do something when onMeasure is called is (I think) to create your own control, extend the ImageView and override onMeasure (just call super.onMeasure and do whatever else you would like to do).如果你这样做,请记住,测量可能会被调用几次不同的参数,所以测量的可能不是实际显示的最终宽度和高度。If you do that, just keep in mind that on Measure may be called several times with different parameters, so whatever is measured may not be the final width and height of what will be actually displayed. 这篇关于什么时候调用View.onMeasure()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-10 14:44