The solution would be to use RecyclerView with the GridLayoutManager. The key is to notify the adapter of changes to deleted items using notifyItemRemoved. There are many options for customization in RecyclerViews, such as nice animation for disappearing elements, rearrangement of remaining elements on the screen, decoration of objects, etc. You can apply all these settings and additional logic around deleting items as needed for your specific problem.
Activities
public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<String> dataSet = getSampleDataSet(); recyclerView = (RecyclerView) findViewById(R.id.grid); recyclerView.setAdapter(new MyAdapter(dataSet)); recyclerView.setLayoutManager(new GridLayoutManager(getApplicationContext(), 2)); } private List<String> getSampleDataSet() { List strings = new ArrayList(); strings.add("one"); strings.add("two"); strings.add("three"); strings.add("four"); strings.add("five"); strings.add("six"); return strings; } }
Adapter
public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> { List<String> dataSet; public MyAdapter(List<String> dataSet) { this.dataSet = dataSet; } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { TextView tileView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false); MyViewHolder myViewHolder = new MyViewHolder(tileView); return myViewHolder; } @Override public void onBindViewHolder(MyViewHolder holder, final int position) { holder.view.setText(dataSet.get(position)); holder.view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dataSet.remove(position); notifyItemRemoved(position);
Action layout
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/grid" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
Mesh element
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridItem" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/colorPrimary" android:textColor="@android:color/white" android:gravity="center" android:text="Tile"/>
Results To: 
After clicking on 4. On a real device, you can see a nice framework animation for this action.

dkarmazi
source share