开发者

Android - Simple Custom View question

I have a custom View in which i drawBitmap and then I scale the View to 1.5 scale factor.

After the scaling (zoom gesture) - I get the width and height of the view and it's the same just like the initial size. Thus, I have:

canvas.scale(1.5, 1.5, 0, 0);
measure(getWidth()*1.5, getHeight()*1.5);

and it calls onMeasure with the correct dimensions:

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(heightMeasureSpec, MeasureSpec.EXACTLY));
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);

    }
}

But after onMeasure is finished, if I get the width and height of the View, it's again the same as before...

And I need it to be the scaled size ..开发者_运维知识库.


I'm not sure, but I think you need to use a Matrix here, apply it to your image/canvas, and then use postscale() method to make it effective. Hope that helps


To resize the View you need to have its parent lay out again. Make two calls on your View: First specify the new size view View.setLayoutParams(LayoutParams), then call View.requestLayout().


There is a method getMeasuredWidth/Height(), that should give you what the View's measured values are at drawing time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜