拖放图标到主屏幕 [英] Drag and Drop icons to Home Screen

查看:223
本文介绍了拖放图标到主屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新: 明白我的问题,这是我需要实现: 从应用程序抽屉主屏幕拖动图标(如果可能的话不是在GridView)像在PIC,

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,

旧(这只是为了了解它的工作原理):

我想实现拖动点击图标从的ListView customView 无容器(列表视图或GridView的... )的同一活动内或其他,这里是一个画面让你了解更多:

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:

但是当我把在右侧区域中的图标的我不看对象,在日志中我看到: I / ViewRootImpl:报告下降的结果:真正的

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

我在这里的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;
    }
}

我的XML文件:

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>

 ...

的任何相关信息或引用(教程文档...)将是非常有益

推荐答案

有一个在添加视图到窗口管理器(WM)。当被拖进一个项目,你长的preSS,创建你自己的项目,位图,并把它添加到WM,以便它可以在不视图边界约束的移动。当您收到ACTION_UP或等效的事件,映射你当前的X,Y的实际观点,即是正下方拖动的项目(矩形班组长可能会有所帮助)。然后,您可以将该产品添加到特定视图。

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.

这篇关于拖放图标到主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆