This the xml in which I am trying to keep one image button on the right and while the left ? I dont why it is not happening though i have set the grvaity too ?
<LinearLayout android:id="@+id/linearLayout1"
android:layout_height="wrap_content" android:gravity="center_horizontal"
android:layout_width="wrap_content" android:layout_gravity="fill">
<ImageButton android:layout_width="wrap_content"
android:layout_gravity="left" android:id="@+id/imageButton1"
android:src="@drawable/arrow_button_left" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:layout_width="wrap_content"
android:layout_gravity="right" android:id="@+id/imageButton2"
android:src="@drawable/arrow_button_right" android:layout_height="wrap_content"></ImageButton>
</LinearLayout>
You should use RelativeLayout
instead of LinearLayout
, and set the layout_alignParentRight
attribute for the second ImageButton
to true
:
android:layout_alignParentRight="true"
so your layout would look like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_height="wrap_content" android:gravity="center_horizontal"
android:layout_width="fill_parent" android:layout_gravity="fill">
<ImageButton android:layout_width="wrap_content"
android:id="@+id/imageButton1"
android:src="@drawable/arrow_button_left"
android:layout_height="wrap_content" />
<ImageButton android:layout_width="wrap_content"
android:id="@+id/imageButton2"
android:src="@drawable/arrow_button_right"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With