简体   繁体   中英

Drag and Drop icons to Home Screen

Update: to understand my question, here is what i need to achieve: Drag icon from App drawer to home screen ( if possible not in a gridview) like in the pic,

在此处输入图片说明

Old (this just to learn how this works):

I'm trying to implement dragging clickable icons from a ListView to a customView with no container( Listview or Gridview... ) inside the same Activity or another, here is a picture for you to understand more:

在此处输入图片说明

but when i put the icon in the right area i don't see the object , in the log i see: I/ViewRootImpl﹕ Reporting drop result: true

在此处输入图片说明

here my code:

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;
    }
}

My XML file:

...
<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>

 ...

Any infos or references (tutorials, docs...) would be very helpful

Have a look at adding a view to the WindowManager(WM). When you long press on an item to be dragged, create your own bitmap of that item and add it to the WM, so that it can be moved without view boundary constraints. When you receive a ACTION_UP or an equivalent event, map your current x,y to the actual view that is directly below the dragged item (Rect classs might be helpful). You can then add this item to that particular view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM