在其他几个帖子下面的建议,我实现了一个圆形按钮,在应用程序中使用:Android的 - 如何定义配置的尺寸形状
:它是使用XML选择实施
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states
-->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false"
android:drawable="@drawable/big_ring_button_unfocused" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/big_ring_button_unfocused" />
<!-- Focused states
-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false"
android:drawable="@drawable/big_ring_button_focused" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/big_ring_button_focused" />
<!-- Pressed
-->
<item android:state_pressed="true" android:drawable="@drawable/big_ring_button_pressed" />
</selector>
的..._聚焦文件的内容(其他人只是改变颜色):
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="@dimen/big_ring_button_inner_radius"
android:thickness="@dimen/big_ring_button_thickness"
android:useLevel="false">
<solid android:color="@color/white" />
</shape>
我想为我的应用中的所有圆角按钮使用此模板,但由于按钮内部的文本发生更改,按钮本身的大小应该改变。
我认为我也许可以以编程方式做到这一点,所以我检查的GradientDrawable的文档 - 有没有方法有改变innerRadius
属性。
目前我每个圆形按钮(选择器,未聚焦,聚焦和按下)有4个XML文件,这是非常丑陋的,并将成为一个颈部疼痛的维护。
我怎样才能使这个按钮的大小(XML或编程)配置?
感谢
我想你可以在正确的尺寸缩放的TextView中设置文本,然后检索尺寸,加大半径尺寸并使用它? – 2014-11-14 14:21:36
@ user3427079,“半径大小的两倍” - 如何在不为此特定按钮创建其他xml的情况下执行此操作? – Vasiliy 2014-11-14 14:35:31
textView.getWidth()* 2,类似于我想像的那样 – 2014-11-14 14:44:11