0

I have tried different ways to resize the thumb size of Seekbar but got no success.
This is the thumb of my Seekbar with pressed effect too:

enter image description here enter image description here
My thumb selector file where I have added these two images to get press effect:

lessons_thumb_selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/lessons_thumb" android:state_pressed="false"/>
    <item android:drawable="@drawable/lessons_pressed"/>
</selector>

And my thumb file where I have resized the thumb selector:

thumb_drawable_lessons.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/lessons_thumb_selector"
        android:width="50dp"
        android:height="50dp"/>
</layer-list>

And my Seekbar tag in layout file where I have used the Seekbar with this thumb is:

    <SeekBar
    android:id="@+id/sBarLessons"
    android:layout_centerInParent="true"
    android:progressDrawable="@drawable/styledprogrees"
    android:thumb="@drawable/thumb_drawable_lessons"
    style="@style/book_categories_seekbar_style"
    />

And style tag in style.xml file is this: 430dp 175dp @color/transparent 100 10dp false And the problem is! everything looks fine when I see in Android Studio layout preview:

enter image description here

But when i execute and install apk on device it shows thumb size the same and dislocated from Seekbar:

enter image description here Note:
- Press effect is working fine.
- Using the same image for 10 inch device and trying to resize it for 7 inch device.
- Please note aligning is not an issue, issue is resizing. I want to reduce the size of thumb proportionately.
- Also generating 9-patch doesn't help in my solution.
- Using Lolipop 5.1.1 version in my devices.

I have tried these solutions too but got no success:
Android SeekBar thumb gets clipped/cut off
dynamically resized Thumb of SeekBar gets clipped above and below, how to draw on top (Z order)?
Android resizing SeekBar thumb width from maximum value

Community
  • 1
  • 1
Hamad
  • 5,096
  • 13
  • 37
  • 65

1 Answers1

0

I had a very similar problem a few days ago. I was trying to style a Switch widget and its thumb was awful (like yours). But original works without any problem. I opened original drawables and found they are 9-patch.

So I converted my images to 9-patch and problem was solved.

This is a thumb (left) and track (right) opened in a Android Studio 9-patch editor (note the markup)

This is a thumb and track

Alexandr Shutko
  • 1,857
  • 2
  • 20
  • 27
  • It looks like I didn't understand question. You are trying to dynamically resize thumb depending on screen size ? – Alexandr Shutko Feb 26 '16 at 06:42
  • yes I want to resize seekbar thumb images from dimens according to device resolution, i have these images for 720 dpi want to resize it for 600 dpi from dimens – Hamad Feb 26 '16 at 07:16
  • Did you try to resize it programmatically and then setThumb() ? – Alexandr Shutko Feb 26 '16 at 07:25
  • tried to getThumb() and set bounds but no success in that too! and there is no method for setting width and height for drawable! – Hamad Feb 26 '16 at 07:47
  • not working! resizing bitmap only works but resizing bitmapDrawable doesn't work! if I resize single bitmap then press effect can not work on seekbar thumb! – Hamad Feb 26 '16 at 10:16
  • http://stackoverflow.com/questions/6501716/android-how-to-create-a-statelistdrawable-programmatically# – Alexandr Shutko Feb 26 '16 at 12:31