我使用的碼是低於:
@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;
//返回super.onDragEvent(事件); }
// 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);
}
}
,幷包含在LinearLayout中的組件(TextView的)是靜態的,通過XML加載的,問題是其他draging一個TextView的TextView的時候會消失,並與他人消失的時候將其刪除。
是否有人知道它是如何去這樣,或如何在LayoutView中實現一個拖動手勢,感謝和欣賞傢伙來到這裏。