package com.loaderman.customviewdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup; public class MyLinLayout extends ViewGroup {
public MyLinLayout(Context context) {
super(context);
} public MyLinLayout(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyLinLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measureWidth = MeasureSpec.getSize(widthMeasureSpec);//获取数值
int measureHeight = MeasureSpec.getSize(heightMeasureSpec);//获取数值
int measureWidthMode = MeasureSpec.getMode(widthMeasureSpec);//获取模式
int measureHeightMode = MeasureSpec.getMode(heightMeasureSpec);//获取模式 int height = 0;
int width = 0;
int count = getChildCount();
for (int i=0;i<count;i++) { View child = getChildAt(i);
measureChild(child, widthMeasureSpec, heightMeasureSpec);
int childHeight = child.getMeasuredHeight();
int childWidth = child.getMeasuredWidth(); height += childHeight;
width = Math.max(childWidth, width);
}
//设置 MeasureSpec.EXACTLY完全 MeasureSpec.UNSPECIFIED 不确定 MeasureSpec.AT_MOST 至多
setMeasuredDimension((measureWidthMode == MeasureSpec.AT_MOST) ? measureWidth
: width, (measureHeightMode == MeasureSpec.EXACTLY) ? measureHeight
: height);
} @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int top = 0;
int count = getChildCount();
for (int i=0;i<count;i++) { View child = getChildAt(i); int childHeight = child.getMeasuredHeight();
int childWidth = child.getMeasuredWidth(); child.layout(0, top, childWidth, top + childHeight);//重新布局控件
top += childHeight;
}
}
}

MeasureSpec常用方法的更多相关文章

  1. 【Android 应用开发】 自定义 圆形进度条 组件

    转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...

  2. 前端开发:Javascript中的数组,常用方法解析

    前端开发:Javascript中的数组,常用方法解析 前言 Array是Javascript构成的一个重要的部分,它可以用来存储字符串.对象.函数.Number,它是非常强大的.因此深入了解Array ...

  3. Jquery元素选取、常用方法

    一:常用的选择器:(李昌辉) 基本选择器 $("#myDiv") //匹配唯一的具有此id值的元素 $("div") //匹配指定名称的所有元素 $(" ...

  4. python浅谈正则的常用方法

    python浅谈正则的常用方法覆盖范围70%以上 上一次很多朋友写文字屏蔽说到要用正则表达,其实不是我不想用(我正则用得不是很多,看过我之前爬虫的都知道,我直接用BeautifulSoup的网页标签去 ...

  5. C# Webbrowser 常用方法及多线程调用

    设置控件的值 /// <summary> /// 根据ID,NAME双重判断并设置值 /// </summary> /// <param name="tagNa ...

  6. list,tuple,dict,set常用方法

    Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...

  7. 记录yii2-imagine几个常用方法

    记录yii2-imagine几个常用方法: //压缩 Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)->save(Yii::g ...

  8. DOM常用方法总结

    DOM(Document Object Model:文档对象模型)为javascript中的一部分,它为访问和修改html文档或xml文档提供了一些编程接口,DOM以对象的形式来描述文档中的内容,以树 ...

  9. JSP内置对象及常用方法

    jsp九大内置对象及四个作用域: 何为作用域 先让我们看看效果: 大概流程是这样的,我们访问index.jsp的时候,分别对pageContext, request, session,applicat ...

随机推荐

  1. 【OF框架】框架规范介绍

    一.目录规范 二.命名规范 三.其它规范

  2. 【转】Lombok Pojo默认初始值问题

    Lombok以注解形式来简化java代码,提高开发效率.比如我们常用的@Builder.@Data.@AllArgsConstructor.@NoArgsConstructor.@ToString等. ...

  3. PHP字符串截取,计算字符串长度

    /** * 字符串截取,支持中文和其他编码 * @param [string] $str [字符串] * @param integer $start [起始位置] * @param integer $ ...

  4. python xml文件解析 及生成xml文件

    #解析一个database的xml文件 """ <databaselist type="database config"> <dat ...

  5. P1736 创意吃鱼法[二维dp]

    题目背景 感谢@throusea 贡献的两组数据 题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她 ...

  6. jwt的原理以及使用

    jwt原理(json web token) 我们之前是使用session实现登录,通过实际密码+盐组成字符串进行md5存入redis或者数据库中,输入的密码与实际校验通过,发送给客户端一个有效时间的t ...

  7. js 异步执行顺序

    参考文章: js 异步执行顺序   1.js的执行顺序,先同步后异步 2.异步中任务队列的执行顺序: 先微任务microtask队列,再宏任务macrotask队列 3.调用Promise 中的res ...

  8. vue中读取excel中数据

    安装xlsx npm install xlsx --save-dev 安装好后在需要的页面 引入插件 import xlsx from 'xlsx' 调用 $('#uploadFile').chang ...

  9. matlab(7) Regularized logistic regression : mapFeature(将feature增多) and costFunctionReg

    Regularized logistic regression : mapFeature(将feature增多) and costFunctionReg ex2_reg.m文件中的部分内容 %% == ...

  10. python func(*args, **kwargs)

    func(*args, **kwargs) *args, **kwargs表示函数的可变参数 *args 表示任何多个无名参数,它是一个tuple **kwargs 表示关键字参数,它是一个dict ...