3

I need to create a custom switch using drawable elements (custom thumb and custom track). I tried several sizes (50x50, 70x70, 100x100) and they all appear out of proportion, unless I use 25x25 icons which look pixelated. How do I scale-down these elements to an appropriate size without lowering its quality?


For example, this is the way it looks now:
enter image description here


This is my switch

<Switch
    android:layout_width="220dp"
    android:layout_height="10dip"
    android:id="@+id/switcSound"
    android:layout_marginTop="55dp"
    android:track="@drawable/switch_track"
    android:thumb="@drawable/switch"
    android:textOff=""
    android:textOn=""
    android:textColor="#FFF"
    android:switchMinWidth="55dp"
   />


This is my switch thumb xml file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/toggle_on" android:state_checked="true"/>
    <item android:drawable="@drawable/toggle_off" android:state_checked="false"/>
</selector>
Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
Alex
  • 1,982
  • 4
  • 37
  • 70
  • try with 9 patch image..see this http://stackoverflow.com/questions/23358822/how-to-custom-switch-button – Aditya Vyas-Lakhan Apr 16 '15 at 07:15
  • 9patch can stretch icons and images, but I need to scale down the already (relatively) big icons, or am I missing something? – Alex Apr 16 '15 at 07:46
  • you should just open the original image in some tools like paint.net and work them to get the correct sizes you need : hdpi, xhdpi etc. – Poutrathor May 03 '15 at 11:44

0 Answers0