Android 拖放视图
我试图在屏幕上拖放一个按钮。我可以拖动,但当我拖放时,会发生以下错误。 日志: xml:-Android 拖放视图,android,Android,我试图在屏幕上拖放一个按钮。我可以拖动,但当我拖放时,会发生以下错误。 日志: xml:- 请帮助我做些什么来克服这个问题。或者如何处理这个按钮不应该引用拖动层它的当前父视图,而是绝对布局。我知道问题是什么:(1)将所有内容移动到一个视图组下,以便所有可移动视图都具有相同的父视图;(2) 放置要移动的视图时,安排更改该视图的父视图。但是今天我想我应该试试我上面建议的:(3)在接受拖放的视图中,复制一个被拖动的视图。将副本作为该视图的子视图附着。返回到原始视图并将其从其父视图中删除。但是如何编码以
请帮助我做些什么来克服这个问题。或者如何处理这个按钮不应该引用拖动层它的当前父视图,而是绝对布局。我知道问题是什么:(1)将所有内容移动到一个视图组下,以便所有可移动视图都具有相同的父视图;(2) 放置要移动的视图时,安排更改该视图的父视图。但是今天我想我应该试试我上面建议的:(3)在接受拖放的视图中,复制一个被拖动的视图。将副本作为该视图的子视图附着。返回到原始视图并将其从其父视图中删除。但是如何编码以修复它请帮助我…thanx..只需使用以下方法:
public interface DropListener {
/**
* Called when an item is to be dropped.
* @param from - index item started at.
* @param to - index to place item at.
*/
void onDrop(int from, int to);
}
你可以看到。还有,让你知道更多细节
<?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>
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;
}
public interface DropListener {
/**
* Called when an item is to be dropped.
* @param from - index item started at.
* @param to - index to place item at.
*/
void onDrop(int from, int to);
}