更新: 明白我的問題,這是我需要實現: 拖動圖標從應用程序抽屜主屏幕(如果可能的話沒有在GridView)像PIC,拖放圖標到主屏幕
舊(這只是爲了學習如何工作):
我試圖實現從拖動點擊圖標一個ListView
與同一活動內沒有容器(Listview or Gridview...
)一customView
或其他,這裏是一個畫面讓你瞭解更多:
但是當我把圖標在右側區域我不「看不到的物體,在日誌中我看到: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;
}
}
我的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>
...
任何相關信息或引用(教程,文檔...)將是非常有益
你在做什麼這一行LinearLayoutAbsListView newParent =(LinearLayoutAbsListView)v; ,是V與ID pane3視圖?如果是這樣的話,當沒有爲這個視圖定義listview時,你如何爲這個視圖設置適配器? – random 2015-04-02 11:02:54
沒有這個代碼與Listview只是爲了讓你知道我做了什麼 – 2015-04-02 11:14:29
再次什麼是LinearLayoutAbsListView中的v newParent =(LinearLayoutAbsListView)v;關於你的xml – random 2015-04-02 11:15:49