自定义view group

来源:互联网 发布:乱世佳人电影结局知乎 编辑:程序博客网 时间:2024/05/17 13:39

https://github.com/wanglianghai/ImageSelectContainer/commit/9a08dc6665bd765aa52f2257c65b361a4934d1aa

//如果不定义,用父视图的给出测量大小@Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) //子视图放的位置, onLayout会被调用多次,注意集合    @Override    protected void onLayout(boolean changed, int l, int t, int r, int b) //设置坐标只要两个值,相对的加       v.layout(horizon, t, horizon += preWidthR, vertical + t);//if判断换行后在计算结果
/**     * Assign a size and position to a view and all of its     * descendants给一个视图和其子视图大小和位置     *     * <p>This is the second phase of the layout mechanism.这是第二个布局进程的阶段     * (The first is measuring). In this phase, each parent calls第一个是测量。在这个阶段,每个父View调用     * layout on all of its children to position them.layout让所有的父的子视图去放自己的位置。     * This is typically done using the child measurements这是一个代表性的用在测量后被储存子视图测量值     * that were stored in the measure pass().</p>     *     * <p>Derived classes should not override this method.继承的class不应该覆盖这方法     * Derived classes with children should override继承类和子类应该覆盖onLayout     * onLayout. In that method, they should在这个方法,他们应该     * call layout on each of their children.</p>调用layout对于他的每一个子类     *     * @param l Left position, relative to parent相对于父视图     * @param t Top position, relative to parent     * @param r Right position, relative to parent     * @param b Bottom position, relative to parent     */    @SuppressWarnings({"unchecked"})    public void layout(int l, int t, int r, int b) {

多看英文意思,要看明白,看明白了就好解决一些方法的调用错误问题

原创粉丝点击