Search code examples
androidlayoutandroid-linearlayoutandroid-relativelayout

put button in one line with same space between all button


i want to put five button in bottom but all button should be with same space means

below is image

enter image description here

Here you can see that second and third image is not in center below is my code i know that i have put padding but still my problem is not solving, i have tried using linearlayout also in that i have done by using weight=1 and width =0 but button is stretching

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:id="@+id/wall"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:drawingCacheQuality="high"
    android:scaleType="fitXY" />

<Button
    android:id="@+id/butRight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"
    android:background="@drawable/check_right" />

<Button
    android:id="@+id/butfav"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/fvrt1" />

<Button
    android:id="@+id/butLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:background="@drawable/check_left" />

<Button
    android:id="@+id/butSetWallpaper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="39dp"
    android:layout_toRightOf="@+id/butLeft"
    android:background="@drawable/chek_wallpaper" />

<Button
    android:id="@+id/butSetRingTone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="36dp"
    android:layout_toLeftOf="@+id/butRight"
    android:background="@drawable/check_ringtone" />

can anybody help me?


Solution

  • I have tried below code it's worked for me try this, just replace with your RelativeLayout

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" >
    
        <ImageView
            android:id="@+id/butLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/check_left" />
    
        <View
            android:id="@+id/butOne"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/check_right" />
    
        <ImageView
            android:id="@+id/butSetWallpaper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/chek_wallpaper" />
    
        <View
            android:id="@+id/butTwo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/check_right" />
    
        <ImageView
            android:id="@+id/butfav"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/fvrt1" />
    
        <View
            android:id="@+id/butThree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/check_right" />
    
        <ImageView
            android:id="@+id/butSetRingTone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/check_ringtone" />
    
        <View
            android:id="@+id/butFour"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/check_right" />
    
        <ImageView
            android:id="@+id/butRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/check_right" />
    </LinearLayout>
    

    out put will be generated as you wish