简体   繁体   中英

Unable to resize the thumb of Seekbar android

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:

在此处输入图片说明 在此处输入图片说明
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:

在此处输入图片说明

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

在此处输入图片说明 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

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)

这是一个拇指和轨道

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM