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. Struts2 S标签 数目字格式化成金额输出(保留两位小数)

    JSP: <s:property value="%{formatDouble(price)}" /> Action:添加 //格式化数字显示 public String ...

  2. js获取本机mac地址,IP地址,计算机名

    <!DOCTYPE HTML> <html> <head> <title>js获取本机mac地址,IP地址,计算机名</title> < ...

  3. scala编程第19章学习笔记(1)——类型参数化

    一.queues函数式队列 函数式队列是一种具有以下三种操作方式的数据结构: head 返回队列的第一个元素. tail 返回除第一个元素之外的队列. scala> import scala.c ...

  4. spark-submit提交作业过程

    1. 作业提交方法以及参数 我们先看一下用Spark Submit提交的方法吧,下面是从官方上面摘抄的内容. # Run application locally on 8 cores ./bin/sp ...

  5. 我所遭遇过的游戏中间件--Scaleform

    我所遭遇过的游戏中间件---Scaleform Scaleform帮助开发人员利用现代系统的三维硬件加速性能创建电影品质的菜单.游戏内HUD,动画纹理.迷你游戏以及移动游戏与应用.Scaleform作 ...

  6. STL队列 之FIFO队列(queue)、优先队列(priority_queue)、双端队列(deque)

    1.FIFO队列   std::queue就是普通意思上的FIFO队列在STL中的模版. 1.1主要的方法有: (1)T front():访问队列的对头元素,并不删除对头元素 (2)T back(): ...

  7. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

  8. JavaScript中将html字符串转化为Jquery对象或者Dom对象

    实例代码: $('<a href="javascript:void(0);" onclick="showUI(this,"4028f65d5d1bb627 ...

  9. 【Storm】学习笔记

    Storm 1 基本概念 1.1 分布式.可扩展.高容错.实时流处理.跨语言 1.2 应用场景 1.2.1 实时分析 1.2.2 在线机器学习 1.2.3 分布式RPC 1.2.4 ETL数据抽取 1 ...

  10. tiny210(s5pv210)移植u-boot(基于 2014.4 版本号)——移植u-boot.bin(打印串口控制台)

    在之前我们移植的代码中,都没看到明显的效果,这节我们实现控制台的信息打印. 在上节.我们看到调用 relocate_code 重定位.在 u-boot 的帮助文档 doc/README.arm-rel ...