LinearLayout测量过程疑问
2015-07-03 17:21
357 查看
疑问:
在LinearLayout的测量方法measureHorizontal里,有个地方存在疑问,widthMode和isExactly赋初值之后,在后面的for循环整个流程里,其值并没有变化,按这个逻辑,如果下面第一份if语句能进去,第二个if则应该一直为true,else语句是永远不会执行的,但为何要这么写呢?
void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
…
final boolean isExactly =
widthMode == MeasureSpec.EXACTLY;
…
for (int i = 0; i < count; ++i) {
…
if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && lp.weight > 0) {
// Optimization: don't bother measuring children who are going to use
// leftover space. These views will get measured again down below if
// there is any leftover space.
if (isExactly) {
mTotalLength += lp.leftMargin + lp.rightMargin;
} else {
final int totalLength = mTotalLength;
mTotalLength = Math.max(totalLength, totalLength +
lp.leftMargin + lp.rightMargin);
}
在LinearLayout的测量方法measureHorizontal里,有个地方存在疑问,widthMode和isExactly赋初值之后,在后面的for循环整个流程里,其值并没有变化,按这个逻辑,如果下面第一份if语句能进去,第二个if则应该一直为true,else语句是永远不会执行的,但为何要这么写呢?
void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
…
final boolean isExactly =
widthMode == MeasureSpec.EXACTLY;
…
for (int i = 0; i < count; ++i) {
…
if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && lp.weight > 0) {
// Optimization: don't bother measuring children who are going to use
// leftover space. These views will get measured again down below if
// there is any leftover space.
if (isExactly) {
mTotalLength += lp.leftMargin + lp.rightMargin;
} else {
final int totalLength = mTotalLength;
mTotalLength = Math.max(totalLength, totalLength +
lp.leftMargin + lp.rightMargin);
}
相关文章推荐
- 使用HTML打开本地应用
- 下拉刷新
- mybaits使用存储过程
- JavaScript事件
- UITextField的文本框部分文本以*的方式来显示
- GRE写作必备句型
- struct和union
- JS设计模式一:单例模式
- Android CheckBox中设置padding无效问题解决方法
- Dynamics AX 2012 - Report labels does not show up in report
- Winform开发之SqlCommand常用属性和方法
- NSLog宏定义,发布后默认不打印
- 设计模式-组合模式
- Win10预览版10162安装及激活图文详细教程
- Win32 Application和Win32 Console Application的区别
- 一个C语言写的2048游戏
- android 仿微信6.2右滑返回
- PeopleSoft 数据库体系结构
- Cross compile perl
- Masonry 当需要把某个控件进行隐藏的时候有警告的解决方案