/*    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. POJ--2570--Fiber Network【floyd+位运算】

    题意:一些公司决定搭建一些光纤网络.单向的,假设从第一点到第二点,有ab两个公司能够搭建,第二点到第三点有ac两个公司能够搭建,第一点到第三点有d公司能够搭建,则第一点到第三点有a.d两个公司能够搭建 ...

  2. Nginx+Memcached+Tomcat集群配置实践(Sticky Session)

    准备工作 创建一个简单的web应用,名为session.其中有两个页面,分别如下所示: 页面login.jsp <%@ page language="java" conten ...

  3. Nginx和Tomcat负载均衡实现session共享

    以前的项目使用Nginx作为反向代理实现了多个Tomcat的负载均衡,为了实现多个Tomcat之间的session共享,使用了开源的Memcached-Session-Manager框架. 此框架的优 ...

  4. [翻译] 用 ObjectiveSugar 扩展NSArray NSDictionary NSSet NSNumber

    source - https://github.com/supermarin/ObjectiveSugar Look like a girl, act like a lady, think like ...

  5. 第十一章 企业项目开发--消息队列activemq

    注意:本章代码基于 第十章 企业项目开发--分布式缓存Redis(2) 代码的github地址:https://github.com/zhaojigang/ssmm0 消息队列是分布式系统中实现RPC ...

  6. C#中图片透明【转】

    C#中图片透明 /// <summary> /// 处理图片透明操作 /// </summary> /// <param name="srcImage" ...

  7. 线程 Timer TimerTask 计时器 定时任务 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. TabLayout ViewPager Fragment 简介 案例 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. JSON学习资料整理

    1.什么是JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使 ...

  10. jQuery的搜索关键词自动匹配插件

    相信许多人都会用过搜索栏自动匹配关键词的功能,无论是像google的专业搜索引擎,还是普通的网站,现在许多都用上了这种关键词匹配技术,本文介绍的用jQuery实现的关键词匹配技术,当然要整合到自己的系 ...