/*    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. Android NDK开发篇(五):Java与原生代码通信(数据操作)

    尽管说使用NDK能够提高Android程序的运行效率,可是调用起来还是略微有点麻烦.NDK能够直接使用Java的原生数据类型,而引用类型,由于Java的引用类型的实如今NDK被屏蔽了,所以在NDK使用 ...

  2. @JVM中对象的引用类型

    JVM中有四种引用类型:强引用.软引用.弱引用.虚引用   强引用(Stong Reference):是指在程序代码中普遍存在的,类似:Object obj = new Object()这类的引用,只 ...

  3. 混沌数学之CircuitChaotic(二维离散电路混沌系统)

    相关软件参见:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/link?url=yg_gE7LUXCg2mXRp-ZZdfRXXIkcNj8YOhvN7 ...

  4. 如何将thick provision lazy zeroed的VMDK文件转换为thick provision eager zeroed?

    详细步骤在此: Enabling clustering features for an existing virtual disk by converting in place(1035823) ht ...

  5. iOS开发-委托实战

    昨天晚上头疼,写了一部分草草的收笔了,早上起来补发一篇文章,昨天关于委托的基本使用和概念都稍微讲了一下,最开始学习委托的时候苹果官网和中文的博客文章看了不少,相似指数比较高.委托在命名要准确,最好是一 ...

  6. Maven Dependencies没有了的解决办法

    头疼的问题,maven Dependencies突然没有了,别的项目都有,个别的却怎么也出不来.  以下是某大神的解决方法,特此转发,以防丢失: 网上搜索了一番,大多都是下面这种做法: 右击 Mave ...

  7. jQuery EasyUI 教程-Tooltip(提示框)

    <!DOCTYPE html> <html> <head> <title>jQuery Easy UI</title> <meta c ...

  8. IOS之NSFileManager 和NSFileHandle

    在现阶手机app的临时缓存文件渐渐增多,在app开发中对于移动设备文件的操作越来越多,我们IOS中对于文件的操作主要涉及两个类NSFileManager 和NSFileHandle,下面我们就看看如何 ...

  9. 5. How to set up a Activity

    1. Create a new xml in "layout" folder "splah.xml" <?xml version="1.0&qu ...

  10. [effictive c++] 条款04 确定对象被使用前已被初始化

    成员初始化 在c和c++ 中,使用为初始化的类型经常会引发不可预料的错误,从而使得我们要花费巨大的时间用于调试查找问题,所以确定对象被使用前已被初始化是个非常好的习惯. 永远在使用之前对对象进行初始化 ...