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. [翻译] 用 ObjectiveSugar 扩展NSArray NSDictionary NSSet NSNumber

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

  2. 关于Themleaf学习总结

    此篇记录学习Themleaf测试的相关用例: study01 Thymeleaf 的HelloWorld级别的例子 简单介绍Thymeleaf的工作流程 study02 使用spring.thymel ...

  3. [Android Pro] 控制硬加速 hardwareAccelerated 在3.0才有的

    从Android3.0 (API level11)开始,Android的2D显示管道被被设计得更加支持硬加速了.硬加速使用GPU承担了所有在View的canvas上执行的绘制操作. 启用硬加速最简单的 ...

  4. Python3.6学习笔记(四)

    错误.调试和测试 程序运行中,可能会遇到BUG.用户输入异常数据以及其它环境的异常,这些都需要程序猿进行处理.Python提供了一套内置的异常处理机制,供程序猿使用,同时PDB提供了调试代码的功能,除 ...

  5. 用Python语言写Hadoop MapReduce程序Writing an Hadoop MapReduce Program in Python

    In this tutorial I will describe how to write a simple MapReduce program for Hadoop in the Python pr ...

  6. CVPR14 图像检索papers

    CVPR14年关于图像检索方面的papers,汇总成一个list,方便阅读. 图像检索 Triangulation embedding and democratic aggregation for i ...

  7. 第一个OC的类

    来源:http://www.cnblogs.com/mjios/archive/2013/04/06/3002814.html 本文目录 一.语法简介 二.用Xcode创建第一个OC的类 三.第一个类 ...

  8. [17] 楼梯(Stairs)图形的生成算法

    感觉这图形怎么看怎么像搓衣板. 顶点数据的生成 bool YfBuildStairsVertices ( Yreal width, Yreal length, Yreal height, Yuint ...

  9. Android之ViewPager循环Demo

    ViewPager是谷歌官方提供的兼容低版本安卓设备的软件包,里面包含了只有在安卓3.0以上可以使用的api.Viewpager现在也算是标配了,如果一个App没有用到ViewPager感觉还是比较罕 ...

  10. Retrofit 简介 wiki 文档

    简介 Type-safe HTTP client for Android and Java by Square, Inc. GitHub主页:https://github.com/square/ret ...