0

Here is my scenario.

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.

Now my screen has three main things.

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.

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.

    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);

       }
    }


});

Now this is not working. A little help would be appreciated.

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

E-Riz
  • 31,431
  • 9
  • 97
  • 134
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

2 Answers2

0

Not sure if it will help, but try to play with setScaleType() trying different options.

image.setScaleType(ScaleType.FIT_CENTER);

Here are listed all the constans the ScaleType class has.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

I must be honest and say i'm not completely sure what you want to do here. But i'm going to assume that you want to make the image function as a background.. If that's what you want, you can do this simply by setting the android:background="@drawable/your_image" attribute on the main layout in your layout file.

If what you want is remove the titlebar, this is done pretty simple by adding this line to your onCreate method in your activity class:

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

If what you want to do is remove the notificationbar, this is also done in the onCreate method in your activity class:

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

I hope this can help you :-) If it's not what you're looking for, then dont hesitate from trying to reformulate what you want.

  • sorry if i didn't explain it properly, please check it i have edited the quesiton. 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*430 – Muhammad Umar Aug 29 '12 at 14:41
  • Try reading the frist answer on this question: http://stackoverflow.com/questions/4756606/how-to-set-height-of-relative-layout-dynamically-in-android – patrickwlarsen Aug 29 '12 at 14:55