Android自定义View

话不多说,上图:

 

LayoutParams是什么?与MeasureSpec有关系吗?

        LayoutParams:直接从表面看就知道,是布局的参数。ViewGroup里面的一个静态类

public static class LayoutParams {
        /**
         * Special value for the height or width requested by a View.
         * FILL_PARENT means that the view wants to be as big as its parent,
         * minus the parent's padding, if any. This value is deprecated
         * starting in API Level 8 and replaced by {@link #MATCH_PARENT}.
         */
        @SuppressWarnings({"UnusedDeclaration"})
        @Deprecated
        public static final int FILL_PARENT = -1;

        /**
         * Special value for the height or width requested by a View.
         * MATCH_PARENT means that the view wants to be as big as its parent,
         * minus the parent's padding, if any. Introduced in API Level 8.
         */
        public static final int MATCH_PARENT = -1;

        /**
         * Special value for the height or width requested by a View.
         * WRAP_CONTENT means that the view wants to be just large enough to fit
         * its own internal content, taking its own padding into account.
         */
        public static final int WRAP_CONTENT = -2;

        public int width;
.
.
.
.
}

那么和MeasureSpec有什么关系呢?

子view通过getChildMeasureSpec()方法传入layoutparams获取对应的MeasureSpec,由于子view的测量。

MeasureSpec是什么呢?

        MeasureSpec是View中的内部类,用于保存宽高的信息(int 累心,32位,高2位标识Mode:UNSPECIFIED、EXACTLY、AT_MOST,低30位标识size)

UNSPECIFIED:不对View大小做限制

EXACTLY:确切的大小:如 100dp

AT_MOST:大小不可超过某个数值,如:match_parent,做大不能超过parent        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值