title: Squaring Up A Relative Layout / Image View
body: <p>So I've read quite a few questions on here as well as tried lots of stuff to try to get this to work. I'm either misunderstanding all of the examples I've read or am looking at the wrong stuff. </p>
  
  <p>What I'm trying to do is set up a relative layout within a relative layout that contains an image view. I want to be able to have the relative layout match the size of the imageview (which I want scaled based on specific screen size) to keep a constant square size. This view will contain buttons as well.When I run the below code I get a square for the image view but the buttons are displayed on the top of the screen. So it appears to me that the imageview is properly scaling down into a square but the layout itself is still matching the overall screen size. I have an XML file set up as follows: </p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/main_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
   &gt;
  
  &lt;RelativeLayout
      android:id="@+id/layout_two"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
  
      &gt;
  
      &lt;ImageView
      android:id="@+id/image_view"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:src="@drawable/bg" /&gt;
  
      &lt;Button
          android:id="@+id/button_one"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/button_one" /&gt;
  
     ....
  
      &lt;/RelativeLayout&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Java code below: </p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  RelativeLayout layoutTwo, mainLayout;
  
  Button buttonOne, buttonTwo, buttonThree, buttonFour, buttonFive;
  Button buttonSix, buttonSeven, buttonEight, buttonNine;
  
  ImageView scalingBackground;
  
  int screenWidth, screenHeight, finalSquare;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
      layoutTwo = (RelativeLayout) findViewById(R.id.layout_two);
      scalingBackground = (ImageView) findViewById(R.id.image_view);
  
      initializeButtons();
  
      squareBackground();
  
  }
  
  
  private void squareBackground() {
  
      screenWidth = mainLayout.getLayoutParams().width;
  
      scalingBackground.getLayoutParams().height = screenWidth;
      scalingBackground.getLayoutParams().width = screenWidth;
      layoutTwo.getLayoutParams().height = screenWidth;
      layoutTwo.getLayoutParams().width = screenWidth;
  
  }
  </code></pre>
  
  <p>Not quite sure whats going on here, I'd appreciate a kick in the right direction. Thanks</p>