Setting height, and width of a relative layout in android
<p>Here is my scenario.</p>

<p>I have an image which is made as per resolution 320*480 (assuming i am using mdpi mobile). I am adding this image as a background to a relative layout.</p>

<p>Now my screen has three main things.</p>

<pre><code>1- Title bar (The standard title bar of android)
2- My relative layout and its sub view image relative layout which is matched parent.
3- My menu bar at the bottom.
</code></pre>

<p>Now since my image is getting stretched in between menu bar and title bar. I want to make it fit the screen. Below is the code I am using.</p>

<pre><code>    mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            public void onGlobalLayout() 
        {
           if (notCreated == true)
           {
               notCreated = false;
           }
           else
           {
               mnHeight = mainLayout.getHeight();
               Rect rect = getRawCoordinatesRect(mainLayout);
               h = getWindowManager().getDefaultDisplay().getHeight() -  
                       - rect.top - mainLayout.getHeight();
// rect.top to remove android standard title bar

               RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(image.getWidth(),LayoutParams.MATCH_PARENT);
               params.topMargin = -1 * rect.top;
               params.bottomMargin = -1 * h;
               image.setLayoutParams(params);

       }
    }


});
</code></pre>

<p>Now this is not working. A little help would be appreciated.       </p>

<p>Note: Actually  I just want to stretch my image relative layout to 320*480. Right now it is sandwitched between title bar and my menu bar. E.g right now its dimensions are 320*400</p>
