title: how to make a child of linearLayout align to parents right programmatically?
body: <p>I have a <code>linearLayout_child</code> inside another <code>linearLayout_parent</code>.</p>
  
  <p>I want to make <code>linearLayout_child</code> aligned to parent's right.</p>
  
  <p>How can I do this?</p>
  
  <p>what if I want all <code>linearLayout_parent</code>'s children be aligned to their parent's right?</p>
  
  <p>I want to do them both programmatically.</p>
  
  <p><strong>update</strong></p>
  
  <p>is there any tool with which I can see the current layout properties and attributes in my Activity's view? The code changes many attributes from the original XMl and it's hard to follow at a specific situation.</p>
  
  <p>here is my xml:</p>
  
  <p>
              </p>
  
  <pre><code>        &lt;MyTextView
              android:id="@+id/navBarDistance"
              style="@style/NavBarDistance"
              android:textSize="19dp"
              android:text="miles"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              /&gt;
  
          &lt;MyTextView
              android:id="@+id/navBarDistanceUnit"
              style="@style/NavBarDistUnit"
              android:textSize="19dp"
              android:text="0.1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="3dp" 
              /&gt;
      &lt;/LinearLayout&gt;
          &lt;LinearLayout
              android:id="@+id/navBarDistanceLayoutRtl"
              android:layout_width="70dp"
              android:layout_height="match_parent"
              android:layout_marginRight="8dp"
              android:layout_marginTop="5dp"
              android:gravity="center_vertical|right"
              android:orientation="horizontal"
              android:visibility="gone"&gt;
  
              &lt;MyTextViewType
                  android:id="@+id/navBarDistanceUnitRtl"
                  style="@style/NavBarDistUnit"
                  android:textSize="19dp"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginRight="3dp"
                  /&gt;
  
              &lt;MyTextViewType
                  android:id="@+id/navBarDistanceRtl"
                  style="@style/NavBarDistance"
                  android:textSize="19dp"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  /&gt;
          &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and here is parts of the code:</p>
  
  <p>the change to AlerterMode and then coming back to non-alrter more makes <code>navBarDistanceLayoutRtl</code> be aligned to left instead of right</p>
  
  <pre><code>            if (bIsAlertMode)
              {
  
  ...
                  if (rtlMode)
                  {
                      width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
                      android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
                      DistanceBar.setMargins(3, 20, 3, 0);
                      view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
                  }
                  else
                  {
                      width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
                      android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
                      DistanceBar.setMargins(3, 20, 3, 0);
                      view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
  
                  }
  
  ...
  
              }
              else
              {
     ...
  
                  if (rtlMode)
                  {
                      width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
                      android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
                      DistanceBar.setMargins(20, 8, 3, 0);
  
                      DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_RIGHT;
  
                      view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
  
                      view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.VISIBLE);
                      view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.GONE);
                      distance = (TextView)view.findViewById(R.id.navBarDistanceRtl);
                      distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnitRtl);
                  }
                  else
                  {
                      width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
                      android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
                      DistanceBar.setMargins(0, 8, 3, 0);
                      view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
  
                      DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_LEFT;
  
                      view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.GONE);
                      view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.VISIBLE);
                      distance = (TextView)view.findViewById(R.id.navBarDistance);
                      distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnit);
  
                  }
  
                  ...
              }
          }
  </code></pre>