问题
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>
回答1:
check this out
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>
回答2:
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
.
回答3:
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
来源:https://stackoverflow.com/questions/14789048/android-how-to-make-some-space-between-buttons-and-make-white-line-above-each-of