当将MeasureSpec.UNSPECIFIED和MeasureSpec.AT_MOST应用? [英] When will MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST be applied?

查看:348
本文介绍了当将MeasureSpec.UNSPECIFIED和MeasureSpec.AT_MOST应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑MeasureSpec.UNSPECIFIED和MeasureSpec.AT_MOST。 我知道,当match_parent或恒定尺寸值被设置为layout_width或layout_height,MeasureSpec.EXACTLY将测量视图当施加

I am a bit confused about MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST. I know that when match_parent or an constant dimension value is set to layout_width or layout_height, MeasureSpec.EXACTLY will be applied when measuring the view.

那么,怎么样MeasureSpec.UNSPECIFIED和MeasureSpec.AT_MOST?

Then, how about MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST?

我理解的是,当layout_width或layout_height设为WRAP_CONTENT,MeasureSpec.UNSPECIFIED将被应用,因为WRAP_CONTENT装置的图的高度或宽度可以是任何尺寸取决于内容。但是很多文章说,WRAP_CONTENT意味着MeasureSpec.AT_MOST。所以我很困惑。我不知道什么时候MeasureSpec.AT_MOST应适用。请帮忙。谢谢。

My understanding is that, when layout_width or layout_height is set to wrap_content, MeasureSpec.UNSPECIFIED will be applied, because wrap_content means the height or width of a view can be any size depending on the content. But many articles said that wrap_content means MeasureSpec.AT_MOST. So I am confused. I don't know when MeasureSpec.AT_MOST should be applied. Please help. Thanks.

推荐答案

如何视图的大小基本定义是这样的:

The basic definition of how a View is sized goes like this:

MeasureSpec.EXACTLY - 视图应该只有这么多的像素,无论它实际上希望有多大是

MeasureSpec.EXACTLY - A view should be exactly this many pixels regardless of how big it actually wants to be.

MeasureSpec.AT_MOST - 视图可以是这样的尺寸或更小,如果测量出要小一些。

MeasureSpec.AT_MOST - A view can be this size or smaller if it measures out to be smaller.

MeasureSpec.UNSPECIFIED - 视图可以不管它的大小必须是为了显示它需要展示的内容

MeasureSpec.UNSPECIFIED - A view can be whatever size it needs to be in order to show the content it needs to show.

MeasureSpec.AT_MOST 将被应用到已设置为 WRAP_CONTENT 的意见如果父视图势必会在尺寸。例如,你的父视图可以被绑定到屏幕大小。这是孩子们也将被绑定到这个大小,但它可能不会那么大。因此,父视图将设置MeasureSpec为 AT_MOST 它告诉孩子,可以是介于0和屏幕尺寸的任何地方。子将不得不作出调整,以确保它被提供的范围内配合。

MeasureSpec.AT_MOST will be applied to views that have been set to WRAP_CONTENT if the parent view is bound in size. For example, your parent View might be bound to the screen size. It's children will be also bound to this size, but it might not be that big. Thus, the parent view will set the MeasureSpec to be AT_MOST which tells the child that it can be anywhere between 0 and screen size. The child will have to make adjustments to ensure that it fits within the bounds that was provided.

在特殊情况下,该边界并不重要。例如,滚动型。在滚动型的情况下,子视图的高度是不相关的。因此,它会提供一个不定的给孩子意见,告诉他们必须是他们可以像高大的孩子。该滚动型将处理图形和安置他们。

In special cases, the bounds do not matter. For example, a ScrollView. In the case of a ScrollView, the height of the child Views are irrelevant. As such, it will supply an UNSPECIFIED to the children Views which tells the children that they can be as tall as they need to be. The ScrollView will handle the drawing and placement for them.

这篇关于当将MeasureSpec.UNSPECIFIED和MeasureSpec.AT_MOST应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆