Question

I want to implement a Drag gesture within a LinearLayout view,and there are some components contained in it,such as TextView,button. Now i use APL level 11,3.0 SDK to design it according to Android offical document.the methods included in my codes are below:

onLongClick() --- trigger the Drag movtion with view.startDrag(clipdate, dragShadow, null,0)

onDrag() ---a drag listener, use view.layout(left, top, right, bottom), refresh the component's appreance has been drag

and problem i come across is , the other components disappear when i drag one in LinearLayou view, and when i drop the drag one ,it disappear with others.

so Plz anyone who can help me tell how it going wrong,or how can i implement drag gesture well with your suggestion. Firstly,thanks and appreciate every gus come here.

No correct solution

OTHER TIPS

the codes i used is below:

@Override
public boolean onLongClick(View view) {
    // TODO Auto-generated method stub
    boolean result = true;
    if(DEBUG){
        Log.d(TAG, "onLongClick ()");
    }
    mLongTouch = true;
    ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
    ClipData dragData = new ClipData((CharSequence) view.getTag(), mTabDragMimeData, item);
    SimeTabDragListener.SimeTabDragShadow myShadow = new SimeTabDragListener.SimeTabDragShadow(view);
    view.startDrag(dragData, myShadow, null, 0);
    return result;
}

@Override
public boolean onDrag(View view, DragEvent event) {
    // TODO Auto-generated method stub
    boolean result = true;
    int action = event.getAction();
    int eventX = (int)event.getX();
    int eventY = (int)event.getY();
    if(DEBUG){
        Log.d(TAG, "onDrag()...event is  "+action + ".... X cor is "+event.getX()+"...Y  cor is"+event.getY());
    }
    view.layout(eventX - mDownOffsetsX, eventY - mDownOffsetsY,
            eventX + mDownViewWidth - mDownOffsetsX, eventY + mDownViewHeight - mDownOffsetsY);
    view.postInvalidate();
    return result;

// return super.onDragEvent(event); }

// drag shadows 
public static class SimeTabDragShadow extends View.DragShadowBuilder {
            private static  Drawable shadow;
            public SimeTabDragShadow(View view) {
                super(view);
                if(DEBUG && view instanceof TextView)
                    Log.d(TAG, "drag view is text");
                shadow = new ColorDrawable(Color.LTGRAY);
            }
            @Override
            public void onProvideShadowMetrics(Point shadowSize,
                    Point shadowTouchPoint) {
                // TODO Auto-generated method stub
                super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
            }
            @Override
            public void onDrawShadow(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDrawShadow(canvas);
            }


        }

and the components(TextView) contained in LinearLayout is static and loaded by XML, problem is other TextView will be disappeared when draging one TextView, and disappear with others when drop it.

is there someone know how it going like this, or how to implement a Drag Gesture within LayoutView, thanks and appreciate guys come here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top