title: Drag/Move ViewGroup in android
body: <p>I have a ViewGroup and I want to move it on screen by finger when user press long click to <code>circleMenu</code> . How can I move <code>ViewGroup</code>? </p>
  
  <p>Here is java :</p>
  
  <pre><code>public class ViewService extends Service implements OnItemSelectedListener,
  OnItemClickListener, OnRotationFinishedListener, OnCenterClickListener, OnLongClickListener {
  
      private WindowManager windowManager;
      CircleLayout circleMenu;
      CircleImageView ciw1, ciw2, ciw3, ciw4;
  
      @Override public IBinder onBind(Intent intent) {
          // Not used
          return null;
      }
  
      @Override public void onCreate() {
          super.onCreate();
  
          //windowsmanager
  
          windowManager = (WindowManager) getSystemService("window");
  
          final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.TYPE_PHONE,
              WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
              PixelFormat.TRANSLUCENT
          );
  
          params.gravity = Gravity.CENTER | Gravity.LEFT;
          params.x = 0;
          params.y = 0;
  
  
          //layout+circleMenu
          LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
          View baseview = li.inflate(R.layout.activity_main, null);
  
          circleMenu = (CircleLayout) baseview.findViewById(R.id.main_circle_layout);
  
          ciw1 = new CircleImageView(this);
          ciw1.setBackgroundResource(R.drawable.twitter);
          ciw2 = new CircleImageView(this);
          ciw2.setBackgroundResource(R.drawable.whatsapp);
          ciw3 = new CircleImageView(this);
          ciw3.setBackgroundResource(R.drawable.cam);
          ciw4 = new CircleImageView(this);
          ciw4.setBackgroundResource(R.drawable.sms);
  
          ciw1.setId(1);
          ciw2.setId(2);
          ciw3.setId(3);
          ciw4.setId(4);
          circleMenu.addView(ciw1);
          circleMenu.addView(ciw2);
          circleMenu.addView(ciw3);
          circleMenu.addView(ciw4);
  
          windowManager.addView(baseview, params);
  
      }
  
      @Override
      public boolean onLongClick(View v) {
  
          return true;
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  
  
      @Override
      public void onItemSelected(View view, String name) {
  
          switch (view.getId()) {
  
          }
      }
  
      @Override
      public void onItemClick(View view, String name) {
  
  
          switch (view.getId()) {
              case 1:
                  Toast.makeText(getApplicationContext(), "twit", Toast.LENGTH_SHORT).show();
  
                  break;
              case 2:
                  Toast.makeText(getApplicationContext(), "what", Toast.LENGTH_SHORT).show();
                  break;
              case 3:
                  Toast.makeText(getApplicationContext(), "cam", Toast.LENGTH_SHORT).show();
                  break;
              case 4:
                  Toast.makeText(getApplicationContext(), "sms", Toast.LENGTH_SHORT).show();
                  break;
  
          }
      }
  
      @Override
      public void onCenterClick() {
          Toast.makeText(getApplicationContext(), R.string.center_click,
              Toast.LENGTH_SHORT).show();
  
  
      }
  
      @Override
      public void onRotationFinished(View view, String name) {
          Animation animation = new RotateAnimation(0, 360, view.getWidth() / 2,
              view.getHeight() / 2);
          animation.setDuration(250);
          view.startAnimation(animation);
      }
  }
  </code></pre>
  
  <p>Here is XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:circle="http://schemas.android.com/apk/res/lazy.launcher"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity" "&gt;
  
  &lt;package.ViewGroup.CircleLayout
      android:id="@+id/main_circle_layout"
      android:layout_width="200dp"
      android:layout_height="200dp"
      android:layout_marginLeft="-80dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      circle:firstChildPosition="East"
      circle:isRotating="true"
      circle:rotateToCenter="true"
      circle:speed="75" &gt;
  
  &lt;/package.ViewGroup.CircleLayout&gt;
  
  &lt;ImageView
      android:id="@+id/toggle"
      android:layout_width="35dp"
      android:layout_height="35dp"
      android:layout_alignParentLeft="true"
      android:layout_marginTop="80dp"
      android:gravity="center"
      android:src="@drawable/ic_launcher" /&gt;
  </code></pre>
  
  <p></p>