Mou*_*ssi 8 java android drag-and-drop view layout-inflater
更新: 了解我的问题,这是我需要实现的:将图标从App抽屉拖动到主屏幕(如果可能的话,不是在gridview中),如图片中所示,

旧(这只是为了了解这是如何工作的):
我正在尝试将一个可点击的图标从一个拖动ListView到一个customView没有容器(Listview or Gridview...)的同一个Activity或另一个,这里有一张图片供您了解:

但是当我把图标放在右边区域时我看不到对象,在日志中我看到:I/ViewRootImpl? Reporting drop result: true

我的代码:
class MyDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
...
case DragEvent.ACTION_DROP:
LinearLayoutAbsListView itemo = (LinearLayoutAbsListView)findViewById(R.id.paneko);
View child = getLayoutInflater().inflate(R.layout.list_item, null);
itemo.addView(child);
break;
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我的XML文件:
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@android:color/background_dark"
android:orientation="horizontal" >
<com.moapps.elfassimounir.simple.LinearLayoutAbsListView
android:id="@+id/paneuj"
android:background="@android:color/background_light"
android:orientation="vertical"
>
<ListView
android:id="@+id/listview1"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</com.moapps.elfassimounir.simple.LinearLayoutAbsListView>
<com.moapps.elfassimounir.simple.LinearLayoutAbsListView
android:id="@+id/paneko"
android:background="@android:color/background_light"
android:orientation="vertical" >
</com.moapps.elfassimounir.simple.LinearLayoutAbsListView>
</LinearLayout>
...
Run Code Online (Sandbox Code Playgroud)
任何信息或参考(教程,文档......)都会非常有用
看一下向 WindowManager(WM) 添加视图。当您长按要拖动的项目时,创建您自己的该项目的位图并将其添加到 WM,以便可以在不受视图边界约束的情况下移动它。当您收到 ACTION_UP 或等效事件时,将当前的 x,y 映射到拖动项目正下方的实际视图(矩形类可能会有所帮助)。然后您可以将此项目添加到该特定视图。
| 归档时间: |
|
| 查看次数: |
1828 次 |
| 最近记录: |