MeasureSpec常用方法
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常用方法的更多相关文章
- 【Android 应用开发】 自定义 圆形进度条 组件
转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...
- 前端开发:Javascript中的数组,常用方法解析
前端开发:Javascript中的数组,常用方法解析 前言 Array是Javascript构成的一个重要的部分,它可以用来存储字符串.对象.函数.Number,它是非常强大的.因此深入了解Array ...
- Jquery元素选取、常用方法
一:常用的选择器:(李昌辉) 基本选择器 $("#myDiv") //匹配唯一的具有此id值的元素 $("div") //匹配指定名称的所有元素 $(" ...
- python浅谈正则的常用方法
python浅谈正则的常用方法覆盖范围70%以上 上一次很多朋友写文字屏蔽说到要用正则表达,其实不是我不想用(我正则用得不是很多,看过我之前爬虫的都知道,我直接用BeautifulSoup的网页标签去 ...
- C# Webbrowser 常用方法及多线程调用
设置控件的值 /// <summary> /// 根据ID,NAME双重判断并设置值 /// </summary> /// <param name="tagNa ...
- list,tuple,dict,set常用方法
Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...
- 记录yii2-imagine几个常用方法
记录yii2-imagine几个常用方法: //压缩 Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)->save(Yii::g ...
- DOM常用方法总结
DOM(Document Object Model:文档对象模型)为javascript中的一部分,它为访问和修改html文档或xml文档提供了一些编程接口,DOM以对象的形式来描述文档中的内容,以树 ...
- JSP内置对象及常用方法
jsp九大内置对象及四个作用域: 何为作用域 先让我们看看效果: 大概流程是这样的,我们访问index.jsp的时候,分别对pageContext, request, session,applicat ...
随机推荐
- VSCode安装程序——java开发
文章:微软为 Java 开发者推出 VSCode 安装程序 文章介绍微软为VSCode提供了开发程序,方便java开发者更好的使用VSCode
- MySQL的索引优化,查询优化
MySQL逻辑架构 如果能在头脑中构建一幅MySQL各组件之间如何协同工作的架构图,有助于深入理解MySQL服务器.下图展示了MySQL的逻辑架构图. MySQL逻辑架构,来自:高性能MySQL My ...
- chrome 調試 node 代碼
(1)node --inspect-brk debug/demo (2)通过 chrome 进行调试 (3) chrome://inspect 进入chrome调试界面 --inspect ...
- Coins in a Line II
There are n coins with different value in a line. Two players take turns to take one or two coins fr ...
- Appium自动化测试教程-自学网-monkeyrunner API
MonkeyRunner API MonkeyRunner工具主要有三个类: MonkeyRunner MonkeyDevice MonkeyImage 官方API文档 :http://www.and ...
- 006——C#关闭窗口 添加FormClosing事件
(一)参考文献:C# 添加FormClosing事件 (二)在 项目名.Designer.cs中的InitializeComponent()添加: this.FormClosing += new S ...
- redis默认端口6379以其名命名,是我孤陋寡闻了,是名性感美女(梅尔兹)
阿莱西亚-梅尔兹Alessia Merz ,这位亚平宁半岛的性感女人,自从结婚之后就逐渐的淡出了人们的实现,曾经的尤文教母已经现在已经是两个孩子的母亲,但是最近的梅尔兹开始蠢蠢欲动,在相夫教子的同时, ...
- learning svn add file execuable
svn propset svn:executable on <file> 为了给svn仓库里的问件添加可执行权限.
- 2017.11.8 Noip2017 考前模拟赛
----------------------------------T1---------------------------------- ——>足球联赛 题目描述 巴蜀中学新一季的足球联赛开 ...
- FCFS,SJF,HRN
1.编写并调试一个单道处理系统的作业等待模拟程序. 作业等待算法:分别采用先来先服务(FCFS),最短作业优先(SJF).响应比高者优先(HRN)的调度算法. 对每种调度算法都要求打印每个作业开始运行 ...