public class ScrollviewSupportMaxHeight extends ScrollView {
   
    public final int MAX_HEIGHT = 150;

    public ScrollviewSupportMaxHeight(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        measureChildren(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), measureHeight(heightMeasureSpec));
    }
   
    private int measureHeight(int heightMeasureSpec) {
        int size = 0;
        if(MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
            size = getChildAt(0).getMeasuredHeight();
        } else {
            size = MeasureSpec.getSize(heightMeasureSpec);
        }
        return size > MAX_HEIGHT ? MAX_HEIGHT : size;
    }
}

实现ScrollviewSupportMaxHeight的更多相关文章

随机推荐

  1. python笔记2-冒泡排序

    前言 面试的时候经常有面试官喜欢问如何进行冒泡排序?这个问题相信能难倒一批英雄好汉,本篇就详细讲解如何用python进行冒泡排序. 一.基本原理 1.概念: 冒泡排序(Bubble Sort),是一种 ...

  2. td顶部对齐

    <td width=568 colspan=3 valign="top" style='width:426.1pt;border:none; border-bottom:so ...

  3. 在windows上搭建C语言开发环境——借助eclipse和MinGW

    0. 前言     [本文目的]     近期在电脑上又一次安装了MinGW,发现MinGW的安装方法和之前的方法稍有差别,全部再写了一篇博文记录一下具体的安装方法.     [本文主要内容]     ...

  4. ubuntu下如何查看软件安装目录以及安装版本

    1)aptitude show 软件名 例如aptitude show kde-runtime 显示如下 ****@ubuntu:~$ aptitude show kde-runtime 软件包: k ...

  5. Web系统自己主动化部署脚本

    Web开发的项目,除了在本地直接执行外,还可能常常须要在server上部署. 写了个自己主动化部署的脚本,仅供參考. 不少地方须要配置路径.个人建议使用绝对路径,不用依赖执行脚本时所在的路径. #!/ ...

  6. there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

    建表语句: create table test_table(   id integer not null auto_increment primary key,   stamp_created tim ...

  7. sql server2005 express和Northwind数据库安装

    最近在学<C#入门经典>的数据库章节时,发现机子上既没有sql server又没书中所说的northwind数据库,想立刻运行下第一个工程DataReading都没法进行.在网上折腾后有了 ...

  8. HDU1226:超级密码(BFS)

    Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进 ...

  9. TPC-E在populate测试Database时需要注意的一些事项

    第一,  安装时不要使用named instance, 默认的instance就好. 否则会报连不上Database. 第二, TPC-E工具文件夹的完整路径中不可以有空格, 否则会在generate ...

  10. 【Android】自己定义控件实现可滑动的开关(switch)

    ~转载请注明来源:http://blog.csdn.net/u013015161/article/details/46704745 介绍 昨天晚上写了一个Android的滑动开关, 即SlideSwi ...