【发布时间】:2023-03-16 12:55:01
【问题描述】:
我需要在 Android 应用程序中自定义 Switch。 我正在使用此代码:
<Switch
android:id="@+id/switchmode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:textOn=""
android:textOff=""
android:switchMinWidth="0dp"
android:thumb="@drawable/switch_bg"
android:track="@drawable/track_bg"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp" />
track_bg 文件是:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switch_track" />
</selector>
switch_bg 文件是:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_enable" />
<item android:state_pressed="true" android:drawable="@drawable/switch_press" />
<item android:state_checked="true" android:drawable="@drawable/switch_check_on" />
<item android:drawable="@drawable/switch_enable" />
</selector>
- switch_check_on 为 32 x 31
- switch_enable 为 32 x 31
- switch_press 为 32 x 31
- switch_track 为 64 x 31
结果是一个拉伸的图像(它应该是一个圆形但它被压扁了):
https://www.dropbox.com/s/07iigspuh3dpfnh/switchstreched.jpg
有什么明显的错误吗?
【问题讨论】:
标签: android layout android-switch stretched