【发布时间】:2013-10-14 03:37:48
【问题描述】:
我想删除按钮视图中文本周围的填充。 第一个屏幕截图是我要实现的结果,第二个屏幕截图是最先进的。
当然,我已经定义了一个自定义的可绘制对象来获取按钮的外观。但即使我将填充属性设置为 0dp,结果也不会改变。
有什么建议吗?
编辑 这是按钮的xml代码
<Button
android:id="@+id/btnCancel"
style="@style/dark_header_button"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:padding="0dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@android:string/cancel" />
这里是样式xml文件:
<style name="dark_header_button">
<item name="android:background">@drawable/bkg_dark_header_button</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowRadius">1</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#ffffff</item>
</style>
这里是可绘制的 xml 文件:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<corners android:radius="10dp" />
<gradient
android:angle="90"
android:endColor="#060606"
android:startColor="#707070"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<corners android:radius="10dp" />
<gradient
android:angle="90"
android:endColor="#707070"
android:startColor="#060606"
android:type="linear" />
<stroke
android:width="0.5dp"
android:color="#2b2b2b" />
</shape>
</item>
</selector>
【问题讨论】:
-
介意也分享你的xml....?
-
“当然,我已经定义了一个自定义的drawable来获得按钮的外观”请告诉我们这个定义,如果你自己定义应该没有填充
-
您的
layout_height属性是否设置为wrap_content?并确保你有 9 个修补过的图像。 -
对不起,我忘记了密码。 @yugidroid 它是和 xml 可绘制的,所以没有 9-patch。是的,
layout_height设置正确。