在Android的自定义开关部件4 [英] Custom switch widget in Android 4
问题描述
我越来越疯狂与开关按钮的Android 4.0。
I am getting crazy with switch buttons in Android 4.
首先,我设置了一个选择作为背景与绘制文件夹中选择两个不同的PNG文件:
First of all, I have set a selector as background with two different PNG files selected from drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/form_switch_no" android:state_checked="false"/>
<item android:drawable="@drawable/form_switch_ok" android:state_checked="true"/>
<item android:drawable="@drawable/form_switch_no"/>
</selector>
但我不知道为什么他们的x缩放。我要管理这种规模,但我试图改变layout_width /身高/体重...没有更迭。
but I don't know why they are x-scaled. I want to manage this size, but I have tried to change layout_width/height/weight... without succes.
我还用作开关的拇指定制PNG文件。我还需要管理这个拇指大小,因为如果我设置纹元和textOff propieties为,拇指得到一个非常小的尺寸。此外,我想改变的拇指垫有关的背景,因为它不居中显示。
I have also a custom PNG file to be used as the thumb of the switch. I also need to manage the size of this thumb, because if I set textOn and textOff propieties as "", thumb gets a very small size. Moreover, I would like to change thumb padding in respect of the background, because It does not appears centered.
下面是我的交换机XML定义:
Here is my Switch XML definition:
<Switch
android:id="@+id/switchUsers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user"
android:textOn=""
android:textOff=""
android:thumb="@drawable/form_switch_slider"
android:track="@drawable/switch_user_selector" />
我曾试图改变图像大小,使他们九补丁的,但我不能达到我的目标。
I have tried to change image sizes and making them nine-patch ones, but I can't reach my target.
任何帮助将AP preciated。谢谢!
Any help will be appreciated. Thank you!
推荐答案
在solucion为非常小的滑块没有文字被解决了的组合:
The solucion for the extremely small slider with no text was solved with a combination of:
android:thumbTextPadding="25dp"
android:textOn=""
android:textOff=""
然后,将小填充在同一拉头的问题是一个9补丁图像的问题。我不得不延长底部和右侧的黑色线条多了一个像素simetrically。
Then, the problem of the small padding in the same slider was a 9-patch image problem. I had to extend bottom and right black lines one more pixel simetrically.
希望这可以帮助别人同样的问题。
Hope this helps someone with the same problem.
这篇关于在Android的自定义开关部件4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!