0
我想拖放一個按鈕在screen.i可以拖動,但是當我放下面的錯誤發生。 logcat的:拖放視圖
12-05 15:03:00.905: E/AndroidRuntime(1009): java.lang.IllegalArgumentException: Given view not a child of [email protected]
12-05 15:03:00.905: E/AndroidRuntime(1009): at android.view.ViewGroup.updateViewLayout(ViewGroup.java:1876)
12-05 15:03:00.905: E/AndroidRuntime(1009): at com.avigma.learning.DragLayer.onDrop(DragLayer.java:131)
12-05 15:03:00.905: E/AndroidRuntime(1009): at com.avigma.learning.DragController.drop(DragController.java:447)
12-05 15:03:00.905: E/AndroidRuntime(1009): at com.avigma.learning.DragController.onTouchEvent(DragController.java:424)
12-05 15:03:00.905: E/AndroidRuntime(1009): at com.avigma.learning.DragLayer.onTouchEvent(DragLayer.java:69)
XML: -
<?xml version="1.0" encoding="utf-8"?>
<com.avigma.learning.DragLayer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:id="@+id/drag_layer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/b" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="-4dp"
android:layout_y="2dp" >
<AbsoluteLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent" >
//This button i am dragging and dropping
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="84dp"
android:layout_y="90dp"
android:background="@null"
android:text="B"
android:textColor="#000000"
android:textSize="35dp"
android:textStyle="bold"
android:typeface="serif" />
</AbsoluteLayout>
</ScrollView>
</AbsoluteLayout>
</com.avigma.learning.DragLayer>
我想我必須更新可移動物體的當前視圖bcoz其refrencing拖動層其父視圖,但在我的XML按鈕目前的觀點是絕對佈局。這錯誤是在onDrop()我提供了代碼: - 。
private boolean drop(float x, float y) {
final int[] coordinates = mCoordinatesTemp;
DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
if (dropTarget != null) {
dropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
if (dropTarget.acceptDrop(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo)) {
dropTarget.onDrop(mDragSource, coordinates[0], coordinates[1],
(int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
mDragSource.onDropCompleted((View) dropTarget, true);
return true;
} else {
mDragSource.onDropCompleted((View) dropTarget, false);
return true;
}
}
return false;
}
請幫那我應該怎麼做才能克服這種issue..or如何處理按鈕建議立即進行刪除d不參考拖動它當前的父視圖,但絕對佈局..我知道什麼問題,要麼(1)在一個ViewGroup下移動所有可移動的視圖有相同的父視圖; (2)安排在視圖被刪除時更改正在移動的視圖的父視圖。但今天我想我會嘗試我上面提出的建議:(3)在接受放置的視圖中,製作被拖動視圖的副本。將該副本附加爲該視圖的子項。回到原來的觀點,並從其parent.But刪除它如何代碼來修復它,請幫我...感謝名單..