** 注:本文参考链接How Android caculates view size
本文例子如下所示:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="20dp" />
</LinearLayout>
过程
计算view大小的过程可以分为以下几个步骤:
- 确定view想要的size(LayoutParams)
- 确定parent view的情况(MeasureSpec)
- 在parent view的限制下,根据view的LayoutParams,确定view的大小
参数
LayoutParams
LayoutParams用于view表示想要的size的模式。有以下三种:
- FILL_PARENT / MATCH_PARENT (-1)
view的size和parent view的size一样大 - WRAP_CONTENT(-2)
view的size仅包裹其内容即可 - 指定的值(>0)
view的size为指定的size大小
MeasureSpec
MeasureSpec表示当前view的“约束”(在onMeasure中传入)。约束含模式mode和数值size,当前view根据mode来决定如何看待其中的size。
mode
mode有三种,如下所示:
- UNSPECIFIED
对当前view的size没有约束 - EXACTLY
当前view的bounds(可以理解成“可以使用的范围”)为确定的size,也可以理解成parent view希望当前view(有强制的意味)使用给定的size - AT_MOST
当前view的大小不可超过指定的size
可以利用MeasureSpec的getMode取出具体值.
size
size为8个byte的int值,mode放在前2个bit中。这里可以利用MeasureSpec的getSize取出size的具体值。
onMeasure过程
view通过onMeasure确定自己的大小。确定自己的大小时,需要的东西有:
- 约束MeasureSpec
- 自己的LayoutParams
- 如果有child view,那么需要获取child view的大小
最终确定当前view的size分别为:
- measureWidth
- measureHeight
single view
以前面例子中的TextView为例,其onMeasure中传入的MeasureSpec为:
- Width
mode:EXACTLY size:parentContentWidth(LinearLayout的宽-padding) - Height
mode:AT_MOST size:parentContentHeight(LinearLayout的高-padding)
注:这里先不解释为什么MeasureSpec是这样的。
TextView的LayoutParams为:
- Width
MATCH_PARENT - Height
WRAP_CONTENT
然后TextView根据约束和LayoutParams确定自己的大小,包括但不限于以下过程:
- 设置宽度为parentContentWidth,考虑margin确定字符可用范围
- 根据字符高度和字体设置(根据是否超过parentContentWidth确定是否换行)等计算字符所占的高度(没有限制)。
- 设置measureWidth和measureHeight
ViewGroup
以前面例子中的LinearLayout为例,假设该LinearLayout为Activity中的root layout其onMeasure中传入的MeasureSpec为:
- Width
mode:EXACTLY size:parentContentWidth(LinearLayout的parent view的宽-padding) - Height
mode:AT_MOST size:parentContentHeight(LinearLayout的parent view的高-padding)
LinearLayout的LayoutParams为:
- Width
MATCH_PARENT - Height
WRAP_CONTENT - Orientation
vertical
然后LinearLayout根据约束和LayoutParams确定自己的大小,包括但不限于以下过程:
- 确定child view的排列方式
- 确定TextView的size
- 确定ImageView的size
- 根据自身的设置,设置measureWidth和measureHeight
要确定child view的size,就要调用child view的onMeasure,传入合适的MeasureSpec,表明parent view对child的约束。
根据parent view的不同module和child view的不同LayoutParams,有如下规则:
- 当parent view的mode是EXACTLY时:
child layout | mode | size | |
---|---|---|---|
exact size | EXACTLY | childSize | Child wants a specific size. |
MATCH_PARENT | EXACTLY | parentContentSize | Child wants to be parent’s size. |
WRAP_CONTENT | AT_MOST | parentContentSize | Child wants to determine its own size. It can not be bigger than parent. |
- 当parent view的mode是AT_MOST时:
child layout | mode | size | |
---|---|---|---|
exact size | EXACTLY | childSize | Child wants a specific size |
MATCH_PARENT | AT_MOST | parentContentSize | Child wants to be parent’s size, but parent’s size is not fixed. Constrain child to not be bigger than parent. |
WRAP_CONTENT | AT_MOST | parentContentSize | Child wants to determine its own size, but it can not be bigger than parent. |
- 当parent view的mode是UNSPECIFIED时:
child layout | mode | size | |
---|---|---|---|
exact size | EXACTLY | childSize | Child wants a specific size. |
MATCH_PARENT | UNSPECIFIED | can not decide yet | Child wants to be parent’s size. Child will decide its own size later. |
WRAP_CONTENT | UNSPECIFIED | can not decide yet | Child wants to be its own size. Child will decide its own size later. |
以例子中的TextView为例:
- LinearLayout的width mode为EXACTLY,TextView的width layout param为MATCH_PARENT
- LinearLayout的height mode为AT_MOST,TextView的height layout param为WRAP_CONTENT
所以TextView的onMeasure会被传入:
- Width
mode:EXACTLY size:parentContentWidth(LinearLayout的宽-padding) - Height
mode:AT_MOST size:parentContentHeight(LinearLayout的高-padding)
TextView可以根据上述约束计算自己的大小。ImageView同理。最后LinearLayout根据ImageView和TextView的大小计算自己的大小。注意这里没有weight的设置,所以onMeasure只运行一次。
如上述有错,请留言告知。
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
hgh pen kaufen
References:
hgh tabletten kaufen
dianabol side effects after one cycle
References:
Valley.Md
DHT is 5 instances more androgenic than testosterone, according to some sources.
As a result, DHT-derived steroids like Anadrol and Proviron, with Anadrol being the most well-known example, are very efficient at growing muscular strength.
When women combine going to the health club with a
healthy consuming plan, they’ll often anticipate to burn about 2-2.5lbs of fats
per week. The first 20mg of Anavar must be taken every single day to get a great sense of how nicely the treatment is tolerating the body.
You can continue the cycle for the complete eight weeks or for a most
of 10 weeks. Of course, Anavar is simpler when combined with a nutritious diet
and train routine.
Insomnia may be experienced by clenbuterol users extra
prone to an excessively energetic nervous system, inflicting hyperactivity (4).
Anxiousness is a common side impact of taking clenbuterol due to its
tendency to shift a person into fight-or-flight mode. Extreme
arousal of the central nervous system might cause an individual to
perceive on a regular basis conditions as threats, negatively affecting their psychological well being.
Any water misplaced from taking clenbuterol is likely to return after a cycle,
making this diuretic impact temporary. You can get it from the black market at the price of more than $100 for a 5-week cycle.
Larger testosterone levels enhance intercourse drive in ladies, this improve in libido generally isn’t enough to be a downside, unless a lady is attempting to remain celibate.
It’s essential to notice that virilization unwanted effects are rare in ladies (who use
average doses of Anavar). And even if they
did happen, they aren’t everlasting so as soon as you stop taking Anavar; your hormones will stability out and these male characteristics are prone to disappear.
So many women use Anavar today, which is why considered one of its nicknames is
– the ‘girl steroid’.
Testosterone might turn out to be necessary from the third week onwards
when pure testosterone levels start to noticeably suppress.
It’s crucial to acknowledge that not all popular combinations are effective.
This may include gentle energy increments, a firming of the
muscle, and a discount in physique fats. The impression of such
adjustments are normally more profound in novices, whereas skilled
users might observe a considerably more regular shift
in the path of improved muscle definition and energy.
Steroid cycles assure results solely when elementary elements like proper
coaching, diet, and rest are met.
Therefore, its results right here appear individualistic, and its full influence (positive or negative)
on ligaments and joints is not absolutely understood.
The advantages and positive results of Winstrol need to be balanced in opposition to
the negatives, including its excessive stage of hepatotoxicity.
This is why most people use Winstrol sparingly and
at occasions when will most likely be of most benefit – similar to before
competitions.
Girls usually look for guidance on how to use Anavar safely
to spice up lean muscle while minimizing the potential drawbacks of anabolic
steroids. By following correct utilization tips and being aware of the dangers, feminine bodybuilders and athletes could make knowledgeable
decisions to succeed in their fitness goals.
Anavar is a gentle steroid that’s often used by feminine bodybuilders to assist increase
muscle mass and power.
Despite the reality that Anavar is exogenous testosterone (as
are all other steroids), it outperforms the competitors by means of fats burning.
Anavar can also be an efficient fats burner because of its
capacity to increase T3 levels in the body. Anavar is usually used as a chopping steroid;
due to this fact, if a woman’s objective is to bulk up and achieve lots of muscle, she ought to
use one other steroid corresponding to testosterone (such as Anadrol).
Other substances, however, are more likely to trigger virilization. Females, then again,
ought to monitor their cholesterol levels to make sure that their blood strain doesn’t rise dangerously.
Ladies who have been using steroids for some time can take a 10mg a day
dose for a period of 1-6 weeks. It’s essential to remember that since such customers are accustomed
to the steroid, their tolerance degree is higher. If nevertheless, you’re feeling uncomfortable on a heavier dose then it’s best to both cease the cycle altogether or reduce the
every day dose. Whereas Winstrol can help contribute to muscle gain in men, it doesn’t excel
on this space in the same means many other steroids do, which is why it’s not used as a bulking steroid.
No explicit time of day is considered greatest for taking Winstrol, and it’ll vary based
on your training or performance schedule. With a half-life of round 9 hours, oral Winstrol does not want to separate the
dosage into multiple every day doses like other steroids.
Its popularity for delivering outcomes is what has stored Winstrol as one
of the in style anabolic steroids for decades.
Oxandrolone presents a wide range of advantages that cater
particularly to the unique needs and necessities of feminine athletes and
bodybuilders. One such benefit lies in its ability to facilitate
fat loss while preserving lean muscle mass. Throughout the chopping part, when the major target shifts towards shedding physique fat, it’s paramount to keep away from muscle loss;
Anavar makes this potential.
Thus, optimizing the dosages in these tandem cycles is
crucial in harnessing the advantages whereas abating potential side effects.
Anavar is a more potent anabolic steroid,
however it also has more potential unwanted side effects.
TRT is a more natural method to enhance testosterone levels, nevertheless it will not be as efficient for some individuals.
When integrating Anavar with other dietary supplements, a strategic strategy is required to optimize performance and well being outcomes.
Additionally, maintaining a stability of electrolytes is essential
to prevent potential imbalances during an Anavar cycle, as this compound may alter fluid
retention and electrolyte ranges.
References:
http://www.valley.md
ipamorelin legal status
References:
Cheap Ipamorelin 5Mg
ipamorelin 10mg reconstitution
References:
peptides cjc 1295 and ipamorelin 10 mg
fragment 176-191 & cjc-1295 & ipamorelin blend
References:
difference between sermorelin and ipamorelin
does ipamorelin require a prescription
References:
ipamorelin uk peptides (https://keller-shields.blogbright.net/cjc-1295-dosage-calculator-and-chart-a-z-guide)