在网格视图中拖动物品

9

我有一个动态行数和3列的网格。在某个时刻只有3行可见。在网格中,我可能会有空单元格。你有没有想过如何为单元格视图实现拖放功能?我希望能够在空单元格中拖动项目。


http://developer.android.com/guide/topics/ui/drag-drop.html - Nikola Despotoski
我需要在Android 2.1中完成这个。 - Buda Gavril
您想在空单元格中拖放项目。 - Jeetendra
请使用此链接访问:http://blahti.wordpress.com/2011/10/03/drag-drop-for-android-gridview/。 - Jeetendra
我会尝试这个,谢谢。 - Buda Gavril
1个回答

1
我希望能添加一个例子、参考资料和一些代码片段。

这里我希望添加一个例子、参考资料和一些代码片段。

Dragging Code Let’s look at the control implementation and how we handle dragging items.

        public class GridViewEx : GridView
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="GridViewEx"/> control.
            /// </summary>
            public GridViewEx()
            {
                // see attached sample
            }

            private void GridViewEx_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
            {
                // see attached sample
            }

            /// <summary>
            /// Stores dragged items into DragEventArgs.Data.Properties["Items"] value.
            /// Override this method to set custom drag data if you need to.
            /// </summary>
            protected virtual void OnDragStarting(DragItemsStartingEventArgs e)
            {
                // see attached sample
            }
     The control has several fields which store the indices of several active items during the drag/drop process. The OnDragStarting

event stores dragged items into the DragEventArgs.Data.Properties[“Items”] value. You would override this method to set custom drag data if you need to. When the user drags an item, we need to show hints as to where the item will be placed if dropped. The standard GridView handles this by sliding adjacent items out of the way. We will implement this exact behavior ourselves in GridViewEx because we need to account for cases where GridView does not support dropping.

    /// <summary>
    /// Shows reoder hints while custom dragging.
    /// </summary>
    protected override void OnDragOver(DragEventArgs e)
    {
        // see attached sample }

    private int GetDragOverIndex(DragEventArgs e)
    {
        // see attached sample 
    }


 Dropping Code
 Next, let’s look at the code that handles dropping.
 We have to override GridView.OnDrop method which is called every time when an end-user drops an item to the new location. Our override

handles dropping for any ItemsPanel that the standard GridView does not support dropping.

 /// <summary>
/// Handles drag and drop for cases when it is not supported by the Windows.UI.Xaml.Controls.GridView control
/// </summary>
protected override async void OnDrop(DragEventArgs e)
{
    // see attached sample
} 
 The OnDrop method includes logic for moving items from one group to another when grouping is enabled, and for new group creation if it

is requested by end-user actions.

如需更多详细信息,您可以参考以下链接使用拖放扩展GridView以进行分组和可变大小的项目

您还可以关注以下链接 Android拖放示例

希望这可以帮助您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接