title: Tried building a sample app where the fragments inside the Grid layout while drag and dropping would swap their place
body: <p>This is my Activity.xml file.</p>
  <pre><code>
            ' &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;GridLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:columnCount=&quot;2&quot;
      android:rowCount=&quot;2&quot;
      android:layout_margin=&quot;10sp&quot;
      tools:context=&quot;.MainActivity&quot;
      android:id=&quot;@+id/gridView&quot;&gt;
  
  
      &lt;fragment
          android:id=&quot;@+id/frag1&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:name=&quot;com.example.drag.Fragment1&quot;
          android:layout_row=&quot;0&quot;
          android:layout_column=&quot;0&quot;
          android:layout_columnWeight=&quot;1&quot;
          android:layout_rowWeight=&quot;1&quot;
          android:layout_gravity=&quot;fill&quot;
          android:layout_margin=&quot;20sp&quot;
          android:background=&quot;@color/teal_200&quot;
          &gt;
  
      &lt;/fragment&gt;
  
      &lt;fragment
          android:id=&quot;@+id/frag2&quot;
          android:name=&quot;com.example.drag.Fragment2&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_row=&quot;0&quot;
          android:layout_column=&quot;1&quot;
          android:layout_gravity=&quot;fill&quot;
          android:background=&quot;@color/teal_200&quot;
          android:layout_columnWeight=&quot;1&quot;
          android:layout_rowWeight=&quot;1&quot;
          android:layout_margin=&quot;20sp&quot;&gt;
  
      &lt;/fragment&gt;
  
      &lt;fragment
          android:id=&quot;@+id/frag3&quot;
          android:name=&quot;com.example.drag.Fragment3&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_row=&quot;1&quot;
          android:layout_column=&quot;0&quot;
          android:layout_gravity=&quot;fill&quot;
          android:background=&quot;@color/teal_200&quot;
          android:layout_columnWeight=&quot;1&quot;
          android:layout_rowWeight=&quot;1&quot;
          android:layout_margin=&quot;20sp&quot;&gt;
  
      &lt;/fragment&gt;
  
      &lt;fragment
          android:id=&quot;@+id/frag4&quot;
          android:name=&quot;com.example.drag.Fragment4&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_row=&quot;1&quot;
          android:layout_column=&quot;1&quot;
          android:layout_gravity=&quot;fill&quot;
          android:background=&quot;@color/teal_200&quot;
          android:layout_columnWeight=&quot;1&quot;
          android:layout_rowWeight=&quot;1&quot;
          android:layout_margin=&quot;20sp&quot;&gt;
  
      &lt;/fragment&gt;
  
  
      &lt;/GridLayout&gt;'
  
  </code></pre>
  <p>This is my MainActivity.java file</p>
  <pre><code>
             `package com.example.drag;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.constraintlayout.widget.ConstraintLayout;
  import androidx.fragment.app.Fragment;
  
  import android.app.Activity;
  import android.app.FragmentTransaction;
  import android.content.ClipData;
  import android.content.ClipDescription;
  import android.graphics.Color;
  import android.icu.text.Transliterator;
  import android.os.Bundle;
  import android.view.DragEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.GridLayout;
  import android.widget.GridView;
  import android.widget.LinearLayout;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          (findViewById(R.id.frag1)).setOnDragListener(new MyDragListener());
          (findViewById(R.id.frag2)).setOnDragListener(new MyDragListener());
          (findViewById(R.id.frag3)).setOnDragListener(new MyDragListener());
          (findViewById(R.id.frag4)).setOnDragListener(new MyDragListener());
  
          MyDragListener myDragListener = null;
  
          myDragListener = new MyDragListener();
          (findViewById(R.id.frag1)).setOnDragListener(myDragListener);
          (findViewById(R.id.frag2)).setOnDragListener(myDragListener);
          (findViewById(R.id.frag3)).setOnDragListener(myDragListener);
          (findViewById(R.id.frag4)).setOnDragListener(myDragListener);
  
  
          (findViewById(R.id.frag1)).setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
                  ClipData dragData = new ClipData(
                          (CharSequence) v.getTag(),
                          new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN},
                          item);
                  View.DragShadowBuilder myShadow = new MyDragShadowBuilder((findViewById(R.id.frag1)));
                  v.startDrag(dragData, myShadow, v, 0);
                  return true;
              }
          });
  
          (findViewById(R.id.frag2)).setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
                  ClipData dragData = new ClipData(
                          (CharSequence) v.getTag(),
                          new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN},
                          item);
                  View.DragShadowBuilder myShadow = new MyDragShadowBuilder((findViewById(R.id.frag2)));
                  v.startDrag(dragData, myShadow,v, 0);
                  return true;
              }
          });
  
          (findViewById(R.id.frag3)).setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
                  ClipData dragData = new ClipData(
                          (CharSequence) v.getTag(),
                          new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN},
                          item);
                  View.DragShadowBuilder myShadow = new MyDragShadowBuilder((findViewById(R.id.frag3)));
                  v.startDrag(dragData, myShadow, v, 0);
                  return true;
              }
          });
  
          (findViewById(R.id.frag4)).setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
                  ClipData dragData = new ClipData(
                          (CharSequence) v.getTag(),
                          new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN},
                          item);
                  View.DragShadowBuilder myShadow = new MyDragShadowBuilder((findViewById(R.id.frag4)));
                  v.startDrag(dragData, myShadow, v, 0);
                  return true;
              }
          });
      }
      class MyDragListener implements View.OnDragListener{
  
          @Override
          public boolean onDrag(View v, DragEvent event) {
              final int action = event.getAction();
              final FragmentTransaction ft = getFragmentManager().beginTransaction();
              switch (action){
                  case DragEvent.ACTION_DRAG_STARTED:
                      if(event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)){
                          v.setBackgroundColor(Color.BLUE);
  
                          return true;
                      }
                      return false;
                  case DragEvent.ACTION_DRAG_ENTERED:
                      v.setBackgroundColor(Color.GREEN);
                      return true;
  
                  case DragEvent.ACTION_DRAG_LOCATION:
                      return true;
  
                  case DragEvent.ACTION_DRAG_EXITED:
                      v.setBackgroundColor(Color.BLUE);
                      return true;
  
                  case DragEvent.ACTION_DROP:
  
                      ClipData.Item item = event.getClipData().getItemAt(0);
                      CharSequence dragData = item.getText();
                     View view = (View) event.getLocalState();
                      ViewGroup owner = (ViewGroup) view.getParent();
                      owner.removeView(view);
                      LinearLayout container1 = (LinearLayout) v;
                      view.setVisibility(View.VISIBLE);
  
  
                      break;
  
  
                  case DragEvent.ACTION_DRAG_ENDED:
  
                      return true;
              }
              return false;
          }
      }
  
  }`
  
  </code></pre>
  <p>Each fragments xml like this</p>
  <pre><code>
           `&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:background=&quot;@color/purple_200&quot;
      tools:context=&quot;.Fragment1&quot;
      &gt;
  
      &lt;TextView
          android:id=&quot;@+id/firstFragment&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_centerInParent=&quot;true&quot;
          android:text=&quot;Slide 1&quot;
          android:textSize=&quot;30dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
      &lt;/TextView&gt;
  
  
  
  &lt;/LinearLayout&gt;`
  
  </code></pre>
  <p>When i tried to run it and start my dragging of fragments. the fragments start adding in the size of container rather than swapping between them. it supposedly work like when i drag one fragment and drop it to the other fragments. the fragments should swap their places.</p>