我用ObjectAnimator旋转了TextView,如下所示: ObjectAnimator rotate = ObjectAnimator.ofFloat(aRotatedTextView, "rotation", 0f, someAngle); 现在,我尝试在长按上拖放旋转的(!)TextView,如下所示: public boolean onLon
ObjectAnimator rotate = ObjectAnimator.ofFloat(aRotatedTextView, "rotation", 0f, someAngle);
现在,我尝试在长按上拖放旋转的(!)TextView,如下所示:
public boolean onLongClick(View view) { ClipData data = ClipData.newPlainText("DragData", (String) view.getTag()); DragShadowBuilder dragShadowBuilder = new View.DragShadowBuilder(view); mDragInProgress = view.startDrag(data, dragShadowBuilder, view, 0); view.setVisibility(View.INVISIBLE); return true; }
会发生什么是在没有旋转的情况下创建DragShadow(角度== 0).我已经看到了很多位图(但没有旋转)的例子,我无法工作.
有没有办法创建旋转的DragShadow?
new OnTouchListener() { @Override public boolean onTouch(final View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: double rotationRad = Math.toRadians(view.getRotation()); final int w = (int) (view.getWidth() * view.getScaleX()); final int h = (int) (view.getHeight() * view.getScaleY()); double s = Math.abs(Math.sin(rotationRad)); double c = Math.abs(Math.cos(rotationRad)); final int width = (int) (w * c + h * s); final int height = (int) (w * s + h * c); DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view) { @Override public void onDrawShadow(Canvas canvas) { canvas.scale(view.getScaleX(), view.getScaleY(), width / 2, height / 2); canvas.rotate(view.getRotation(), width / 2, height / 2); canvas.translate((width - view.getWidth()) / 2, (height - view.getHeight()) / 2); super.onDrawShadow(canvas); } @Override public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { shadowSize.set(width, height); shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); } }; view.startDrag(null, shadowBuilder, view, 0); ... }