问题描述
当我试图扩大我的画布,以一场平局SCALED观点,我的观点实际上是按比例,但鉴于是越来越剪裁。 (可能是因为它的布局参数?)
When I'm trying to scale my canvas to a draw SCALED view, my view is actually scaled, but view is getting clipped. (probably because of its layout parameters?)
public void onDraw(Canvas canvas) {
canvas.scale(2f, 2f);
view.draw(canvas);
}
简单的图片:
simple image:
图像后,新的OnDraw调用,例如,当我点击这个按钮:
image after new onDraw called, for example when I click this button:
按钮应该是全尺寸的帆布时缩放。你有什么想法如何解决呢?
The button should be full sized when canvas is scaled. Do you have any ideas how to solve it?
P.S。呼叫
view.invalidate();
view.requestLayout();
没有帮助。
我用 MyDragShadowBuilder
,因为我想我的看法是双尺寸,当我拖动视图。
I'm using MyDragShadowBuilder
because I want my view to be double sized when I drag the view.
private final class MyDragShadowBuilder extends DragShadowBuilder {
public MyDragShadowBuilder(View view) {
super(view);
}
@Override
public void onDrawShadow(Canvas canvas) {
final View view = getView();
if (view != null) {
canvas.scale(2f, 2f);
view.draw(canvas);
} else {
Log.e("DragShadowBuilder", "Asked to draw drag shadow but no view");
}
}
我想补充我的看法到我绝对布局的实现与WRAP_CONTENT布局属性。
I add my view into my Absolute Layout implementation with WRAP_CONTENT layout properties
推荐答案
我遇到了同样的麻烦。过了一段时间我找到了一种方法,使其工作:)这个缩放由4倍的原始图。
I ran into the same trouble. After some time i found a way to make it work :)This scales the original view by a factor of 4.
private static class MyDragShadowBuilder extends View.DragShadowBuilder {
private static final int SCALING_FACTOR = 4;
public MyDragShadowBuilder(View view) {
super(view);
}
@Override
public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
View v = getView();
final int width = v.getWidth() * SCALING_FACTOR;
final int height = v.getHeight() * SCALING_FACTOR;
shadowSize.set(width, height);
shadowTouchPoint.set(width / 2, height / 2);
}
@Override
public void onDrawShadow(Canvas canvas) {
canvas.scale(SCALING_FACTOR, SCALING_FACTOR);
getView().draw(canvas);
}
}
这篇关于查看不适合在画布上规模画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!