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 ...
随机推荐
- C++——虚函数表解析
转自:https://blog.csdn.net/haoel/article/details/1948051 前言 C++中的虚函数的作用主要是实现了多态的机制.关于多态,简而言之就是用父类型指针指 ...
- 常用实验报告LaTex 模板
目录 模板1-无首页有表格头 模板2-有首页 模板1-无首页有表格头 % -*- coding: utf-8 -*- \documentclass{article} \usepackage{listi ...
- Django modle基础样版
定义一个基类模版, from django.db import models class ModelBase(models.Model): """ "" ...
- GPT分区格式
1. GPT定义 全局唯一标识分区表(GUID partition table, 缩写:GPT)是一个实体硬盘的分区表的结构布局的标准.它是可扩展固件接口(UEFI)标准的一部分,被用于替代BIOS系 ...
- Python Multiprocessing 多进程,使用多核CPU计算 并使用tqdm显示进度条
1.背景 在python运行一些,计算复杂度比较高的函数时,服务器端单核CPU的情况比较耗时,因此需要多CPU使用多进程加快速度 2.函数要求 笔者使用的是:pathos.multiproces ...
- 某网站的videojs的配置及操作
某网站的videojs的配置及操作 一.总结 一句话总结: 多参照参照别人的例子就好,省事 1.videojs如何获取用户当前视频的位置? this.currentTime() 2.回到视频开始处? ...
- CentOS升级Openssl至openssl-1.1.0
1.查看原版本 wget http://www.openssl.org/source/openssl-1.1.0c.tar.gz openssl version 2.解压安装tar zxf opens ...
- jquery点击显示或隐藏
点击第一个dd,给第一li添加class,点击第二个dd,给第二个li添加class,以此类推 $(function(){ $("dd > a").click(fun ...
- 46、[源码]-Spring容器创建-注册BeanPostProcessors
46.[源码]-Spring容器创建-注册BeanPostProcessors 6.registerBeanPostProcessors(beanFactory);注册BeanPostProcesso ...
- 找到一些经验,关于使用thymeleaf时遇到的一些问题
最近一直在使用spring boot,所以自然而然的使用了thymeleaf,但是我想说习惯了jsp之后使用thymeleaf真实觉得不顺手,在使用thymeleaf中也遇到了一些问题,在这里记录一下 ...