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

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

问题描述

更新:
了解我的问题,这里是我需要实现的:
将图标从应用程序抽屉拖动到主屏幕(如果可能不在gridview中)像在图片中





旧(这只是为了了解这是如何工作的):



我正在尝试从 ListView 拖动可点击的图标到 customView ,没有容器( Listview或Gridview ... )在同一个Activity或其他内容中,这里是一张图片让您了解更多:





但是当我放在右侧区域中的图标我没有看到对象,在日志中我看到: I / ViewRootImpl:报告丢弃结果:true / p>



这里我的代码:

  MyDragListener类实现View.OnDragListener {
@Override
public boolean onDrag(View v,DragEvent event){
int action = event.getAction();
开关(event.getAction()){
...
case DragEvent.ACTION_DROP:
LinearLayoutAbsListView itemo =(LinearLayoutAbsListView)findViewById(R.id.paneko);
查看child = getLayoutInflater()。inflate(R.layout.list_item,null);
itemo.addView(child);
break;
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
返回true;
}
}

我的XML文件:

  ... 
< LinearLayout
android:layout_width =match_parent
android:layout_height =0dp
android:layout_weight =2
android:background =@ android:color / background_dark
android:orientation =horizo​​ntal>

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

...

任何信息或引用(教程, docs ...)会很有帮助

解决方案

看看添加一个视图到WindowManager(WM )。当您长时间按下要拖动的项目时,请创建您自己的该项目的位图并将其添加到WM中,以便可以移动而无需视图边界约束。当您收到ACTION_UP或等效事件时,将当前的x,y映射到直接位于拖动项目下方的实际视图(Rect类可能有帮助)。然后,您可以将该项目添加到该特定视图。


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.

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

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