title: Change position of view Programmatically
body: <p>I have added xml layout to the main layout in this way:</p>
  
  <pre><code>View customView = LayoutInflater.from(requireContext()).inflate(R.layout.anim_map_toolbar, null);
  FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
      params.gravity = Gravity.RIGHT;
      params.rightMargin = 20;
      params.topMargin = 20;
      customView.setLayoutParams(new FrameLayout.LayoutParams(params));
  View animationView = customView.findViewById(R.id.anim_toolbar);
  mainConstraintLayout.addView(customView);
  </code></pre>
  
  <p>But this layout appeared on <em>top and left of main layout</em>. I want to change the position to top right with the margin of the top and right of the main layout !!!</p>
  
  <p>I have used </p>
  
  <p>params.gravity = Gravity.RIGHT;</p>
  
  <p>params.rightMargin = 20;</p>
  
  <p>params.topMargin = 20; </p>
  
  <p>but it did not work and still view is on the right and top position !!!</p>
  
  <p>This is the main layout xml:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout 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"
      tools:context=".fragment.MapFragment"
      android:id="@+id/main_constraintLayout"&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>This is anim_map_toolbar.xml layout:</p>
  
  <pre><code>&lt;android.support.v7.widget.LinearLayoutCompat
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="56dp"
      android:layout_height="56dp"
      android:orientation="horizontal"
      android:background="@drawable/animate_toolbar_style"
      android:gravity="center"&gt;
  
      &lt;android.support.v7.widget.AppCompatImageView
          android:id="@+id/imv_setting"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="10dp"
          android:layout_gravity="center"
          android:adjustViewBounds="false"
          android:cropToPadding="false"
          app:srcCompat="@drawable/ic_settings" /&gt;
  &lt;/android.support.v7.widget.LinearLayoutCompat&gt;
  </code></pre>