Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
108 views
in Technique[技术] by (71.8m points)

java - 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,

enter image description here

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:

enter image description here

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...