当我尝试将画布缩放到“绘制缩放”视图时,实际上是缩放了视图,但是视图被裁剪了. (可能是因为其布局参数?)
public voID onDraw(Canvas canvas) { canvas.scale(2f, 2f); vIEw.draw(canvas);}
简单的图像:
调用新onDraw之后的图像,例如,当我单击此按钮时:
缩放画布时,按钮应为全尺寸.您有任何解决方法的想法吗?
ps.呼叫
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布局属性的绝对布局实现中
解决方法:
我遇到了同样的麻烦.一段时间后,我找到了一种使它起作用的方法:)
这会将原始视图缩放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); }}
总结 以上是内存溢出为你收集整理的android-视图在画布比例上不适合画布全部内容,希望文章能够帮你解决android-视图在画布比例上不适合画布所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)