user2567369
user2567369

Reputation:

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?

Upvotes: 1

Views: 1765

Answers (5)

Kamal Bunkar
Kamal Bunkar

Reputation: 1452

Why all of you doing trick with code. In android coding there is option available to give space between item.

  <Space
        android:id="@+id/space1"

        android:layout_below="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        /> 

Just use this whenever you want. simple. hope this will help you.

Upvotes: 0

Suau
Suau

Reputation: 4738

Wrap the buttons in a LinearLayout and put spacings between each button (i also added one at the beginning and one after the last one, remove them if you don't want it).

assign a layout_weight for each spacing, don't set a weightSum on the LinearLayout.

Enjoy.

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/wall"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawingCacheQuality="high"
            android:scaleType="fitXY" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <Button
                android:id="@+id/butRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/check_right" />

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />

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

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <Button
                android:id="@+id/butLeft"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/check_left" />

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <Button
                android:id="@+id/butSetWallpaper"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/chek_wallpaper" />

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <Button
                android:id="@+id/butSetRingTone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/check_ringtone" />

            <!-- this is for the spacing -->
            <View
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_weight="1" />
        </LinearLayout>

    </FrameLayout>

Upvotes: 0

Siddhpura Amit
Siddhpura Amit

Reputation: 15078

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

Upvotes: 1

Vipul Purohit
Vipul Purohit

Reputation: 9827

Its a bit dirty solution but It'll work :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/aaaa"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <Button
            android:id="@+id/butRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:gravity="center"
            android:minWidth="48dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bbbb"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <Button
            android:id="@+id/butfav"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:gravity="center"
            android:minWidth="48dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/cccc"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:minWidth="48dp"
        android:orientation="vertical" >

        <Button
            android:id="@+id/butLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:gravity="center"
            android:minWidth="48dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ddd"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <Button
            android:id="@+id/butSetWallpaper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:gravity="center"
            android:minWidth="48dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/gggg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <Button
            android:id="@+id/butSetRingTone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:minWidth="48dp" />
    </LinearLayout>

</LinearLayout>

Upvotes: 0

goodm
goodm

Reputation: 7295

I always use LinearLayout to achieve this and instead Buttons I'm using ImageView.

Upvotes: 2

Related Questions