Android:如何停止自定义按钮从表单中拍摄所有可用的单元格空间?
-
14-11-2019 - |
题
我设计了彩色的Android按钮可赌灯,并将它们放入桌面。问题是Android的默认按钮不占用整个单元格空间,但我的滑雪桌(请参阅拟议图片)。如何调整XML,以便我的滑动刀像默认按钮一样留下一点空间?我粘贴了底部的XML代码。
自定义按钮:
默认按钮:
xml代码:
.
<?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:angle="90" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />
<corners android:radius="10dip" />
<padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip"></padding>
</shape></item>
<item android:state_focused="true"><shape>
<gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />
<corners android:radius="10dip" />
<padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" />
</shape></item>
<item><shape>
<gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/red" />
<corners android:radius="10dip" />
<padding android:bottom="5dip" android:left="5dip" android:right="5dip" android:top="5dip" />
</shape></item>
</selector>
感谢您的帮助:)
解决方案
Did you try to use the Top, Left, Bottom and Right attributes of items ? See : How to add padding to gradient <shape> in Android?
Alternatively, in your final layout that uses the button, you could use the attribute : android:layout_margin(Right,Left,Top,Bottom)