Bugdr0id
Bugdr0id

Reputation: 3063

Android - Switch track height

I want to have a custom Switch which I can define the Thumb and Track drawables.

Setting the thumb (no problem here):

android:thumb="@drawable/switch_button_selector"

Setting the track:

android:track="@drawable/switch_bg"

switch_bg is a drawable (image) on res/drawable folder and it is not a 9 patch image.

Happens that this drawable is being resized in height.

I want to keep its original size (width/height) without stretching the drawable.

Note: The thumb is bigger (in height) than the track.

Upvotes: 2

Views: 2829

Answers (1)

Eyal Biran
Eyal Biran

Reputation: 5746

You need to have the switch_bg image the exact same size as the thumb resource.

2 options for that:

1) Edit the image (png/etc) to have transparent spacing where it is needed to match the size of the thumb

2) Create a new drawable resource file of layer-list and add the switch_bg as a child. There you can set inner padding so that the overall resource will fit in size to the thumb

Upvotes: 4

Related Questions