Reputation: 641
I have a RelativeLayout
with 2 Button
s 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 Button
s miss their position
See the image below
But i want my RelativeLayout
be like this:
What is wrong?
Upvotes: 2
Views: 13338
Reputation: 641
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:
and this works. thanks everybody
Upvotes: 5
Reputation: 1980
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'.
Upvotes: 0
Reputation: 21181
<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>
Upvotes: 0