1

I have two buttons with xml background , i want to keep some space between them, because that are past exactly on each other , also i want to put white line above them , i will give you how i tried but it doesn't work with me

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"

    android:orientation="horizontal"

    android:weightSum="2" >

    <Button
        android:background="@drawable/button_selector"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:textStyle="bold"
        android:text="@string/b_save" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:background="@drawable/button_selector"
        android:text="@string/b_cancel" />
</LinearLayout>

xml background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <padding android:top="10dip"
        android:bottom="10dip"/>



    <!-- Gradient Bg for listrow -->
    <gradient
        android:useLevel="false"
        android:angle="270"
        android:centerColor="#000000"
        android:endColor="#FFFFFF"
        android:startColor="#808080" />
</shape>

enter image description here

LinCR
  • 391
  • 3
  • 6
  • 14

3 Answers3

4

check this out

enter image description here

bg_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <padding android:top="10dip"
        android:bottom="10dip"/>



    <!-- Gradient Bg for listrow -->
    <gradient
        android:useLevel="false"
        android:angle="270"
        android:centerColor="#808080"
        android:endColor="#000000"
        android:startColor="#FFFFFF" />
</shape>

button_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <padding android:top="10dip"
        android:bottom="10dip"/>



    <!-- Gradient Bg for listrow -->
    <gradient
        android:useLevel="false"
        android:angle="270"
        android:centerColor="#000000"
        android:endColor="#808080"
        android:startColor="#FFFFFF" />
</shape>

your xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:orientation="horizontal"
    android:background="@drawable/bg_selector"
    android:weightSum="2" >

    <Button
        android:background="@drawable/bg_selector"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:textStyle="bold"
        android:layout_marginRight="4dip"
        android:layout_marginLeft="10dip"
        android:text="@string/b_save" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="10dip"
        android:background="@drawable/bg_selector"
        android:text="@string/b_cancel" 
        android:textStyle="bold"/>
</LinearLayout>
rupesh
  • 2,865
  • 4
  • 24
  • 50
William Kinaan
  • 28,059
  • 20
  • 85
  • 118
1

Use the following code in your XML to draw a Horizontal line:

<View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="#ColorValue" />

To draw a Vertical line, just alter the values of android:layout_width and android:layout_height.

Swayam
  • 16,294
  • 14
  • 64
  • 102
  • what is that ? where i can put it ? – LinCR Feb 09 '13 at 14:24
  • i need something to put in the background xml because i will use it too much – LinCR Feb 09 '13 at 14:26
  • The above code will draw a line of any color according to the `ColorValue` you provide. If you use it in the Horzontal LinearLayout after the first button and before the second one, it will draw a line between them. Again, if you use it in a Vertical LinearLayout, it will draw a line above/below the elements. Simply put, use this to draw a line wherever you want. – Swayam Feb 09 '13 at 14:28
  • Well, I dont think you can inject this in your xml background. You would have to copy and paste this code wherever you want the line to be drawn. – Swayam Feb 09 '13 at 14:30
  • thanks to you , +1 to you , but i believe that there is something else becuae go to your mobile and try to edit any contact , at the buttton you will see that there is a separator not like you did, second , i want something to put in the background xml, because that background wil use it to one button and sometimes to many buttons so i think that there is a way other that copying and pasting your code , right? – LinCR Feb 09 '13 at 14:31
  • 1
    Well, yeah.. I definitely get your point. I am just saying that I am not aware of the way how to do it by putting it in background xml and then applying in all the elements. Maybe someone else would be able to help you. Good luck! :) – Swayam Feb 09 '13 at 14:36
0

Pur 1) android:layout_marginTop="10dp" and
2) android:layout_marginBottom="10dp" in xml and this should suffice your work,

the 1st point will keep distance from top and 2nd point will keep distance from bottom

Alexander Zaldostanov
  • 2,907
  • 4
  • 30
  • 39