extends android.view.ViewGroup两种实现
/* private int measureHeight(int heightMeasureSpec) {
int count = getChildCount();
int rowCount = 1;
int left = 0;
int top = 0;
int right = left + getMeasuredWidth();
int childHeight = (count == 0) ? 0 : getChildAt(0).getMeasuredHeight();
int childWidth;
int totalWidth = left;
int totalHeight = top;
// 最后两个child是EditText和ImageButton
int editWidth = getChildAt(count - 2).getMeasuredWidth();
int buttonWidth = getChildAt(count - 1).getMeasuredWidth();
for (int i = 0; i < count - 2; i++) {
childWidth = getChildAt(i).getMeasuredWidth();
// 加上当前childView超出右边界换行。
if (totalWidth + childWidth > right) {
rowCount++;
totalWidth = left;
}
totalWidth += childWidth;
getChildAt(i).setLeft(totalWidth - childWidth);
getChildAt(i).setRight(totalWidth);
getChildAt(i).setTop(childHeight * (rowCount - 1));
getChildAt(i).setBottom(childHeight * rowCount);
}
// 加上最后两个childView超过右边界换行。
if (totalWidth + editWidth + buttonWidth > right) {
rowCount++;
totalWidth = left;
}
totalWidth += editWidth + buttonWidth;
// 倒数第2个childView:收件人编辑框EditText。
getChildAt(count - 2).setLeft(totalWidth - editWidth - buttonWidth);
getChildAt(count - 2).setRight(totalWidth - buttonWidth);
getChildAt(count - 2).setTop(childHeight * (rowCount - 1));
getChildAt(count - 2).setBottom(childHeight * rowCount);
// 倒数第1个childView:addContact按钮。
getChildAt(count - 1).setLeft(right - buttonWidth);
getChildAt(count - 1).setRight(right);
getChildAt(count - 1).setTop(childHeight * (rowCount - 1));
getChildAt(count - 1).setBottom(childHeight * rowCount);
totalHeight += childHeight * rowCount;
return totalHeight;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
View v = null;
for (int i = 0; i < getChildCount(); i++) {
v = getChildAt(i);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if(changed) {
layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
}*/
private int measureHeight(int heightMeasureSpec) {
int count = getChildCount();
int rowCount = 1;
int left = 0;
int top = 0;
int right = left + getMeasuredWidth();
int childHeight = (count == 0) ? 0 : getChildAt(0).getMeasuredHeight();
int childWidth;
int totalWidth = left;
// 最后两个child是EditText和ImageButton
int editWidth = getChildAt(count - 2).getMeasuredWidth();
int buttonWidth = getChildAt(count - 1).getMeasuredWidth();
for (int i = 0; i < count - 2; i++) {
childWidth = getChildAt(i).getMeasuredWidth();
// 加上当前childView超出右边界换行。
if (totalWidth + childWidth > right) {
rowCount++;
totalWidth = left;
}
totalWidth += childWidth;
}
// 加上最后两个childView超过右边界换行。
if (totalWidth + editWidth + buttonWidth > right) {
rowCount++;
totalWidth = left;
}
totalWidth += editWidth + buttonWidth;
return top + childHeight * rowCount;
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
int rowCount = 1;
int left = 0;
int right = left + getMeasuredWidth();
int childHeight = (count == 0) ? 0 : getChildAt(0).getMeasuredHeight();
int childWidth;
int totalWidth = left;
int totalHeight = childHeight;
// 最后两个child是EditText和ImageButton
int editWidth = getChildAt(count - 2).getMeasuredWidth();
int editHeight = getChildAt(count - 2).getMeasuredHeight();
int buttonWidth = getChildAt(count - 1).getMeasuredWidth();
View view = null;
for (int i = 0; i < count - 2; i++) {
view = getChildAt(i);
childWidth = view.getMeasuredWidth();
// 加上当前childView超出右边界换行。
if (totalWidth + childWidth > right) {
rowCount++;
totalHeight += childHeight;
totalWidth = left;
}
totalWidth += childWidth;
view.layout(totalWidth - childWidth, childHeight * (rowCount - 1),
totalWidth, childHeight * rowCount);
}
// 加上最后两个childView超过右边界换行。
if (totalWidth + editWidth + buttonWidth > right) {
rowCount++;
totalHeight += childHeight;
totalWidth = left;
}
totalWidth += editWidth + buttonWidth;
view = getChildAt(count - 2);
view.layout(totalWidth - editWidth - buttonWidth,
totalHeight - childHeight + (childHeight - editHeight)/2,
totalWidth - buttonWidth, totalHeight);
view = getChildAt(count - 1);
view.layout(right - buttonWidth, totalHeight - childHeight,
right, totalHeight);
if(changed) {
layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
}
public class RecipientEditor extends ViewGroup {
public RecipientEditor(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).measure(MeasureSpec.UNSPECIFIED,
MeasureSpec.UNSPECIFIED);
}
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
setMeasuredDimension(measuredWidth, measureHeight(heightMeasureSpec));
}
extends android.view.ViewGroup两种实现的更多相关文章
- Xamarin Android Fragment的两种加载方式
android Fragment的重点: 3.0版本后引入,即minSdk要大于11 Fragment需要嵌套在Activity中使用,当然也可以嵌套到另外一个Fragment中,但这个被嵌套的Fra ...
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)
09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntim ...
- android环境下两种md5加密方式
在平时开发过程中,MD5加密是一个比较常用的算法,最常见的使用场景就是在帐号注册时,用户输入的密码经md5加密后,传输至服务器保存起来.虽然md5加密经常用,但是md5的加密原理我还真说不上来,对md ...
- android studio gradle 两种更新方法更新
android studio gradle 两种更新方法更新 第一种.Android studio更新 第一步:在你所在项目文件夹下:你项目根目录gradlewrappergradle-wrapper ...
- 【转】在Android Studio中下载Android SDK的两种方式(Android Studio3.0、windows)
在Android Studio中下载Android SDK的两种方式(Android Studio3.0.windows) 方式一.设置HTTP Proxy1. 打开Settings2. 点击HTTP ...
- Android学习—下载Android SDK的两种方式
在Android Studio中下载Android SDK的两种方式 Android studio下载地址:http://www.android-studio.org/ 方式一.设置HTTP Prox ...
- Android视频播放的两种方式介绍
1.在Android 中播放视频的方式有两种: 第一种方式是使用MediaPlayer 结合SurfaceView 来播放,通过MediaPlayer来控制视频的播放.暂停.进度等: 通过Surfac ...
- Android 线程 thread 两种实现方法
原文链接: http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thr ...
- Android—— 线程 thread 两种实现方法!(转)
原文地址:http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thre ...
随机推荐
- 一种基于ES5的JavaScript继承
关于JavaScript继承,方式非常多,包含compile-to-javascript的语言TypeScript, CoffeeScript以及站点MDN, GitHub, Modernizr各种p ...
- CAShapeLayer的path动画
CAShapeLayer的path动画 效果 源码 https://github.com/YouXianMing/Animations // // CAShapeLayerPathController ...
- Android之多媒体扫描过程
转自:http://blog.csdn.net/yan8024/article/details/6620359下面是系统图 MediaScannerReceiver会在任何的ACTION_B ...
- UT-Austin大学在Image search and large-scale retrieval方面的一系列papers
WhittleSearch: Interactive Image Search with Relative Attribute Feedback. A. Kovashka, D. Parikh, a ...
- P值(P-value),“差异具有显著性”和“具有显著差异”
郑冰刚提到P值,说P值的定义(着重号是笔者加的,英文是从WikiPedia摘来的): P值就是当原假设为真时,比所得到的样本观察结果更极端的结果出现的概率. The P-value is the pr ...
- C 语言:返回两个数组中第一个相同元素的指针(我用了loop 、goto loop标签)
// // main.c // Pointer_search // // Created by ma c on 15/8/2. // 要求:通过指针查找,实现比较两个有序数组中的元素,输出两个 ...
- [7] 金字塔(Pyramid)图形的生成算法
顶点数据的生成 bool YfBuildPyramidVertices ( Yreal width, Yreal length, Yreal height, YeOriginPose originPo ...
- 第五章 类加载器ClassLoader源码解析
说明:了解ClassLoader前,先了解 第四章 类加载机制 1.ClassLoader作用 类加载流程的"加载"阶段是由类加载器完成的. 2.类加载器结构 结构:Bootstr ...
- Spark踩坑记:共享变量
收录待用,修改转载已取得腾讯云授权 前言 前面总结的几篇spark踩坑博文中,我总结了自己在使用spark过程当中踩过的一些坑和经验.我们知道Spark是多机器集群部署的,分为Driver/Maste ...
- 【系统】supervisor支持多进程
[program:deployworker] directory = /etc/ansible/easyAnsible/app/deploy/ command = python Deploy.py p ...