5

拖动阴影的默认外观和位置是过去的视图,使其透明并以您的触摸为中心。我希望它看起来坚固,并且从您的触摸开始视图。

我已经下降了 DragShadowBuilder 并覆盖了“onProvideShadowMetrics”和“onDrawShadow”。我已经得到了我想要的定位,但我不知道如何关闭透明。

这是创建我的 dragShadowBuilder 和 dragShadowBuilder 类的调用的触摸侦听器:

private OnTouchListener onTouchListener = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            Item current = (Item) ((View) v.getTag()).getTag();
            //ClipData data = ClipData.newPlainText("test", "testText");
            View dragView = (View) v.getTag();//the on touch view is just the "grid" image.  It holds the whole view in it's tag
            DragShadowBuilder shadowBuilder = new ItemDragShadowBuilder(dragView, 
                                new Point(v.getWidth()/2, v.getHeight()/2));
            v.startDrag(null, shadowBuilder, current, 0);
            dragView.setVisibility(View.INVISIBLE);
            return true;
        } else {
            return false;
        }       
    }

};

private static class ItemDragShadowBuilder extends View.DragShadowBuilder {

    private Point touchPoint = null;
    private Point sizePoint = null;
    private View dragView = null;

    public ItemDragShadowBuilder(View dragView, Point touchPoint) {
        super();
        sizePoint = new Point(dragView.getWidth(), dragView.getHeight());
        this.touchPoint = touchPoint;
        this.dragView = dragView;
    }

    @Override
    public void onProvideShadowMetrics (Point size, Point touch) {
        size.set(sizePoint.x, sizePoint.y);
        touch.set(touchPoint.x,touchPoint.y);
    }

    @Override
    public void onDrawShadow(Canvas canvas) {
        dragView.draw(canvas);
        //How do I change the transparency?
        //super.onDrawShadow(canvas);
    }



}

这是我当前的屏幕,其中有一个项目被拖动:

我当前的屏幕

注意透明的外观。当您长按订阅并选择“重新订购”时,我希望它看起来类似于下面的 Google Current 应用程序。您会注意到视图看起来很坚固。

谷歌潮流

我怎样才能使我的拖动阴影变得坚实?

4

0 回答 0