当我尝试将画布缩放到绘制SCALED视图时,我的视图实际上是缩放的,但视图会被剪裁。 (可能是因为它的布局参数?)
public void onDraw(Canvas canvas) {
canvas.scale(2f, 2f);
view.draw(canvas);
}
简单图片:
调用新的onDraw后的
图像,例如当我单击此按钮时:
缩放画布时,按钮应为全尺寸。你有任何想法如何解决它?
P.S。致电
view.invalidate();
view.requestLayout();
无济于事。
我正在使用MyDragShadowBuilder
因为我希望在拖动视图时我的视图是双倍大小。
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布局属性将我的视图添加到Absolute Layout实现中
答案 0 :(得分:4)
我遇到了同样的麻烦。过了一段时间,我找到了一种方法让它工作:) 这会将原始视图缩放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);
}
}