Android DragShadowBuilder停留在接触点的中心

Android DragShadowBuilder停留在接触点的中心,第1张

概述有人可以在以下方面帮助我吗? 1.它不应粘在接触点上,而应从任何点开始拖动. 2.DragShadowBuilder视图应重新设置动画,但不要将其放置在正确的目标上.解决方法:我通过创建自定义View.DragShadowBuilder类实现了这一点.相同的代码是:publicclassCustomDragShadowBuilderexten

有人可以在以下方面帮助我吗?
 1.它不应粘在接触点上,而应从任何点开始拖动.
 2. DragShadowBuilder视图应重新设置动画,但不要将其放置在正确的目标上.

解决方法:

我通过创建自定义view.DragShadowBuilder类实现了这一点.

相同的代码是:

public class CustomDragShadowBuilder extends VIEw.DragShadowBuilder {VIEw v;public CustomDragShadowBuilder(VIEw v) {    super(v);    this.v=v;}@OverrIDepublic voID onDrawShadow(Canvas canvas) {    super.onDrawShadow(canvas);    /*Modify canvas if you want to show some custom vIEw that you want      to animate, that you can check by putting a condition passed over      constructor. Here I'm taking the same vIEw*/     canvas.drawBitmap(getBitmapFromVIEw(v), 0, 0, null);}@OverrIDepublic voID onProvIDeShadowMetrics(Point shadowSize, Point touchPoint) {/*Modify x,y of shadowSize to change the shadow vIEw    according to your requirements. Here I'm taking the same vIEw wIDth and height*/     shadowSize.set(v.getWIDth(),v.getHeight());/*Modify x,y of touchPoint to change the touch for the vIEw  as per your needs. You may pass your x,y position of finger  to achIEve your results. Here I'm taking the lower end point of vIEw*/    touchPoint.set(v.getWIDth(), v.getHeight());  }}

要将视图转换为从here获取的位图:

private Bitmap getBitmapFromVIEw(VIEw vIEw) {    //define a bitmap with the same size as the vIEw    Bitmap returnedBitmap = Bitmap.createBitmap(vIEw.getWIDth(), vIEw.getHeight(),Bitmap.Config.ARGB_8888);    //Bind a canvas to it    Canvas canvas = new Canvas(returnedBitmap);    //Get the vIEw's background    Drawable bgDrawable =vIEw.getBackground();    if (bgDrawable!=null)         //has background drawable, then draw it on the canvas        bgDrawable.draw(canvas);    else         //does not have background drawable, then draw white background on the canvas        canvas.drawcolor(color.WHITE);    // draw the vIEw on the canvas    vIEw.draw(canvas);    //return the bitmap    return returnedBitmap;}

尽管这是一个古老的问题,但对于想要使用自定义DragShadowBuilder的其他人可能会有所帮助.

代码中的注释不言自明,有关更多信息,请告诉我.
希望能帮助到你.

总结

以上是内存溢出为你收集整理的Android DragShadowBuilder停留在接触点的中心全部内容,希望文章能够帮你解决Android DragShadowBuilder停留在接触点的中心所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1077416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存