Android的自定义按钮保证金 [英] Android custom button margin
本文介绍了Android的自定义按钮保证金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义按键布局
I have a custom button layout
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="@color/pres1"
android:endColor="@color/pres2" android:angle="270" />
<stroke android:width="5dp" android:color="@color/stro3" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="20dp"
android:right="10dp" android:bottom="20dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:endColor="@color/focu1"
android:startColor="@color/focu2" android:angle="270" />
<stroke android:width="5dp" android:color="@color/stro2" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="20dp"
android:right="10dp" android:bottom="20dp" />
</shape>
</item>
<item>
<shape>
<gradient android:endColor="@color/norm1"
android:startColor="@color/norm2" android:angle="270" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="20dp"
android:right="10dp" android:bottom="20dp" />
</shape>
</item>
</selector>
而对于低于铺陈
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/all_white">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:textColor="@color/all_red" />
<Button android:id="@+id/mq_categories" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Browse Quiz Categories"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_random" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Enter Random Quiz"
android:background="@drawable/custom_button" />
</LinearLayout>
产生以下输出
我需要添加按钮之间有一些余量,任何帮助AP preciated ..
I need to add some margin between buttons, Any help appreciated..
推荐答案
就这样来做。
<Button android:id="@+id/mq_categories"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Browse Quiz Categories"
android:background="@drawable/custom_button"
android:layout_marginBottom="5dp"/>
这样,您设置的5密度无关的像素上的第一个按钮底部的边距。
This way you set a margin of 5 density independent pixels on the bottom of your first button.
这篇关于Android的自定义按钮保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文