Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to align one Image button right while the other one the left

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>
like image 843
Gainster Avatar asked Dec 02 '22 02:12

Gainster


1 Answers

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>
like image 178
rekaszeru Avatar answered Dec 05 '22 01:12

rekaszeru