3
有誰可以幫我關於以下 -
1.它不應該堅持觸摸點,它應該從任何點開始拖動。
2. DragShadowBuilder視圖應當回退,而不會拖放到正確的目標上。Android DragShadowBuilder粘在觸摸點的中心
有誰可以幫我關於以下 -
1.它不應該堅持觸摸點,它應該從任何點開始拖動。
2. DragShadowBuilder視圖應當回退,而不會拖放到正確的目標上。Android DragShadowBuilder粘在觸摸點的中心
我通過創建自定義View.DragShadowBuilder類來實現此目的。
代碼相同的是:
public class CustomDragShadowBuilder extends View.DragShadowBuilder {
View v;
public CustomDragShadowBuilder(View v) {
super(v);
this.v=v;
}
@Override
public 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);
}
@Override
public 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。
在代碼中的註釋是不言自明的,更多信息讓我知道。 希望它有幫助。
面對同樣的問題。讓我們知道您是否有任何解決方案。 – AndroidHacker