Android Switch拇指图像拉伸 [英] Android Switch thumb image stretched

查看:173
本文介绍了Android Switch拇指图像拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要Android应用程序中的自定义Switch。
我正在使用此代码:

I need a custom Switch in Android application. I'm using this code:

<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文件为:

track_bg file is:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item                               android:drawable="@drawable/switch_track" />
</selector>

switch_bg文件为:

switch_bg file is:

<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

    • switch_check_on is 32 x 31
    • switch_enable is 32 x 31
    • switch_press is 32 x 31
    • switch_track is 64 x 31
    • 结果是拉伸后的图像(应该是一个圆形,但被压碎了):

      The result is a stretched image (it should be a circle but it is crushed):

      https://www.dropbox.com/s/07iigspuh3dpfnh/switchstreched.jpg

      有任何明显的错误吗?

      推荐答案

      创建 9-patch 图片,并指定 Android 应该如何拉伸它。您可以在此处

      Create 9-patch image and specify how it should be stretched by Android. You can read more here

      这篇关于Android Switch拇指图像拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆