2

I have a RelativeLayout with 2 Buttons inside.

One Button has layout_alignParentLeft="true" property and the other button has layout_alignParentRight="true"

I want set a background on my RelativeLayout that show an image in the middle. I have a play.9.png in my drawable and use following code:

<RelativeLayout
    android:id="@+id/relativeLayout12"
    android:layout_width="fill_parent"
    android:layout_height="70dp" 
    android:background="@drawable/play" // background line
 >

    <Button
        android:id="@+id/bAbout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="but1" />

    <Button
        android:id="@+id/bSync"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="but2" />
</RelativeLayout>

But when i use background line, my Buttons miss their position

See the image below enter image description here

But i want my RelativeLayout be like this:

enter image description here

What is wrong?

sunil
  • 6,444
  • 1
  • 32
  • 44
aTa
  • 641
  • 2
  • 8
  • 20

3 Answers3

5

finally i do it guys i used this code:

<RelativeLayout
    android:id="@+id/relativeLayout12"
    android:layout_width="fill_parent"
    android:layout_height="70dp" 
    android:background="@drawable/play" // background line
 >

    <Button
        android:id="@+id/bAbout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="but1" />

    <ImageView
         android:layout_width="fill_parent"
         android:layout_height="match_parent"
         android:scaleType="fitXY"
         android:src="@drawable/play" />

    <Button
        android:id="@+id/bSync"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="but2" />
</RelativeLayout>

and my result was like:

enter image description here

and this works. thanks everybody

aTa
  • 641
  • 2
  • 8
  • 20
0
<RelativeLayout
android:id="@+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="70dp" 
android:background="@drawable/play" // background line
>

<Button
    android:id="@+id/bAbout"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="but1" />

<Button
    android:id="@+id/bSync"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="but2" />
</RelativeLayout>
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
0

I think you should remove

 android:layout_alignParentBottom="true"
 android:layout_alignParentTop="true"

from both the buttons and set the button height to 'fill_parent'.

himanshu
  • 1,990
  • 3
  • 18
  • 36