0

enter image description hereI have a RelativeLayout and I have some TextViews & ImageViews inside it. I have an image set as a background for the RelativeLayout whose height is more than the total height of the child views. So, it's leaving some blank space apart form child views at the bottom. So, how can I avoid this blank space? I mean, is it possible to make the layout height exactly equal to the total height of the child views without considering the height of the layout's background image?

Ex:

<RelativeLayout android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:background="@drawable/bg_image">
    <TextView />
    <ImageView /> 
</RelativeLayout/>

Here, height of 'bg_image' is more than total height of TextView & ImageView. So, it leaves some blank space after TextView & ImageView

Manjunath
  • 2,063
  • 2
  • 29
  • 60

3 Answers3

0

You can try with fill_parent option.. i dont know how many controls are there in your XML Layout.. But may be fill_parent will help you..

Ameer Moaaviah
  • 1,530
  • 12
  • 27
Seema
  • 77
  • 8
  • Yes now from picture its clear.. You can set image as fill parent and assign weight to textview and imageview.. For example, `` – Seema Apr 02 '13 at 07:33
  • But, the child views (TextView & ImageView) should take their normal heights. instead, RelativeLayout should shrink according to child views height. – Manjunath Apr 02 '13 at 07:36
  • give total weight as weightsum in relative layout and then layout weight to textview and imageview.. – Seema Apr 02 '13 at 07:38
0

Try the following code

<RelativeLayout android:layout_width="fill_parent" 
        android:layout_height="fill_parent" android:background="@drawable/bg_image">
    <TextView />
    <ImageView /> 
</RelativeLayout/>
Ameer Moaaviah
  • 1,530
  • 12
  • 27
0

I believe the problem is that the RelativeLayout calculates it's height from it's background image. Try setting a 9-patch image instead. It will then stretch as much as needed to fill the layout, which should have android:layout_height="wrap_content"

stan0
  • 11,549
  • 6
  • 42
  • 59
  • Yes, seems like 9-patch is the solution... But, I am worried about the gradient. Background image has a varying gradient. – Manjunath Apr 02 '13 at 09:17
  • It's possible to make a 9-patch with a gradient. Search for it. I don't keep those resources and can't just look and tell you how it's done :( – stan0 Apr 02 '13 at 09:24