Android imitates Launcher3 to realize the function of dragging and dropping app icons at will to exchange positions

1 Overview

  In the Launcher development of the recent app, it is necessary to implement the imitation Launcher3 to drag and drop the app icon arbitrarily and then move it, and then exchange the position with other app icons and drag to which position is near the app icon to occupy which position, and the occupied position moves to the next position. function development

2. Imitation Launcher3 to realize the function of dragging and dropping the app icon at will to exchange the position

   2.1 Create drag and drop interface DragGridListener

  import android.view.View;

public interface DragGridListener {
	/**
	 * 重新排列数据
	 * @param oldPosition
	 * @param newPosition
	 */
	public void reorderItems(int oldPosition, int newPosition);
	
	
	/**
	 * 设置某个item隐藏
	 * @param hidePosition
	 */
	public void setHideItem(int hidePosition);
	
	
	/**
	 * 删除某个item
	 * @param hidePosition
	 */
	public void removeItem(int hidePosition);
	

}

2.2 Create drag and drop adapter class DragItemAdapter.java

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widg

Guess you like

Origin blog.csdn.net/baidu_41666295/article/details/126519427