When will MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST be applied?

前端 未结 2 542
太阳男子
太阳男子 2020-12-08 00:28

I am a bit confused about MeasureSpec.UNSPECIFIED and MeasureSpec.AT_MOST. I know that when match_parent or an constant dimension valu

2条回答
  •  猫巷女王i
    2020-12-08 01:27

    A MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirement for either the width or the height. A MeasureSpec is comprised of a size and a mode. There are three possible modes:

    UNSPECIFIED

    The parent has not imposed any constraint on the child. It can be whatever size it wants. 
    

    EXACTLY

    The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be. 
    

    AT_MOST

    The child can be as large as it wants up to the specified size. 
    

    MeasureSpecs are implemented as ints to reduce object allocation. This class is provided to pack and unpack the tuple into the int

提交回复
热议问题