【问题标题】:Drag and drop GridView which allows adding items to existing items as well as reordering拖放允许将项目添加到现有项目以及重新排序的 GridView
【发布时间】:2014-08-10 21:15:10
【问题描述】:

我正在写一个启动器。

它有一个 GridView,其中包含应用程序和应用程序文件夹。

我希望能够重新排序 GridView...这是很容易的部分,因为我在下面查看的库提供了重新排序:

https://github.com/askerov/DynamicGrid

https://github.com/mrKlar/PagedDragDropGrid

但是,我还希望能够将我拖动的项目添加到文件夹中,这与 Google Now Launcher 的工作方式完全相同。机制是,在您长按应用程序开始拖放后,如果您将鼠标悬停在另一个项目上,它将允许您将其添加到文件夹(如果它是文件夹)或创建文件夹(如果它是应用程序)。如果您将鼠标悬停在项目的边缘附近,它会重新排序而不是将其添加到项目中。

我不想从头开始写这篇文章,但我找不到任何拖放 GridView(或 ListView)的示例,其中包含重新排序和添加。

有没有人有一个库,一些示例代码,或者一个粗略的想法?

【问题讨论】:

    标签: android android-listview drag-and-drop android-gridview


    【解决方案1】:

    你很幸运,我也在写一个启动器!

    你可以对所有的图标做一个setOnDragListener(new Yourclass())

    Yourclass内,你可以:

    class Yourclass implements View.OnDragListener{
    
        @Override
        public boolean onDrag(View v, DragEvent event) {
            final int action = event.getAction();
            switch (action) {
                case DragEvent.ACTION_DRAG_STARTED:
                    // do nothing
                    break;
                case DragEvent.ACTION_DRAG_ENTERED:
                    //Code for folder
    
                case DragEvent.ACTION_DROP:
                    if (event.getAction()==DragEvent.ACTION_DROP) {
                        //save folder?
                    }
                    return true;
                case DragEvent.ACTION_DRAG_ENDED:
                    //do nothing
                default:
                    break;
            }
            return true;
        }
    }
    

    确保Yourclass 与您的 longclicklistener 位于同一文件中

    但是,我自己编写了所有启动器代码,因此这可能不适用于您的库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-15
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-20
      相关资源
      最近更新 更多