/*    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两种实现的更多相关文章

  1. Xamarin Android Fragment的两种加载方式

    android Fragment的重点: 3.0版本后引入,即minSdk要大于11 Fragment需要嵌套在Activity中使用,当然也可以嵌套到另外一个Fragment中,但这个被嵌套的Fra ...

  2. 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 ...

  3. android环境下两种md5加密方式

    在平时开发过程中,MD5加密是一个比较常用的算法,最常见的使用场景就是在帐号注册时,用户输入的密码经md5加密后,传输至服务器保存起来.虽然md5加密经常用,但是md5的加密原理我还真说不上来,对md ...

  4. android studio gradle 两种更新方法更新

    android studio gradle 两种更新方法更新 第一种.Android studio更新 第一步:在你所在项目文件夹下:你项目根目录gradlewrappergradle-wrapper ...

  5. 【转】在Android Studio中下载Android SDK的两种方式(Android Studio3.0、windows)

    在Android Studio中下载Android SDK的两种方式(Android Studio3.0.windows) 方式一.设置HTTP Proxy1. 打开Settings2. 点击HTTP ...

  6. Android学习—下载Android SDK的两种方式

    在Android Studio中下载Android SDK的两种方式 Android studio下载地址:http://www.android-studio.org/ 方式一.设置HTTP Prox ...

  7. Android视频播放的两种方式介绍

    1.在Android 中播放视频的方式有两种: 第一种方式是使用MediaPlayer 结合SurfaceView 来播放,通过MediaPlayer来控制视频的播放.暂停.进度等: 通过Surfac ...

  8. Android 线程 thread 两种实现方法

    原文链接: http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thr ...

  9. Android—— 线程 thread 两种实现方法!(转)

    原文地址:http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thre ...

随机推荐

  1. strchr实现

    char* strchr(char*s,charc) { while(*s!='\0'&&*s!=c) { ++s; } return*s==c?s:NULL; } // strchr ...

  2. Vim global命令和重复操作

    Vim global命令和重复操作 Vim global命令允许我们在某个指定模式的所有匹配行上运行可执行的 Ex 命令,缩写形式为 :g,其处理重复工作的效率极高. 一.Vim global命令介绍 ...

  3. PHP自己定义安装

    ① 自己定义安装(先要在管理里停止apache服务,再卸载apache.再安装时不须要重新启动电脑) apache+php+mysql+phpmyadmin自行安装 我们建议大家,安装的时候安装到同一 ...

  4. Java输入输出处理技术2

    7.从键盘输入 从键盘输入一行字符,并显示到屏幕上. package io; import java.io.*; public class ReadAndWrite { public static v ...

  5. C 语言:返回两个数组中第一个相同元素的指针(我用了loop 、goto loop标签)

    // //  main.c //  Pointer_search // //  Created by ma c on 15/8/2. //  要求:通过指针查找,实现比较两个有序数组中的元素,输出两个 ...

  6. parameter server学习

    关于parameter server的学习: https://www.zybuluo.com/Dounm/note/517675 机器学习系统相比于其他系统而言,有一些自己的独特特点.例如: 迭代性: ...

  7. js中replace的用法

    replace方法的语法是:stringObj.replace(rgExp, replaceText) 其中stringObj是字符串(string),reExp可以是正则表达式对象(RegExp)也 ...

  8. file not found app文件

    昨天svn迁移.然后又一次check out之后编译遇到这个错误. Ld Build/Products/Debug-iphonesimulator/wiseCloudCrmTests.xctest/w ...

  9. vs2013 密钥_

    vs2013 密钥 最佳答案: BWG7X-J98B3-W34RT-33B3R-JVYW9

  10. 87. 再谈变体型Variant

    在85. BASIC和LotusScript中的Variant一文中.我提到了BASIC风格的语言中的变体型Variant.由于下述种种原因.在LotusScript中常常要用到变体型. 1.     ...