Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

android - Changing size of seekbar thumb

I'm using a drawable for seekbar thumb with

android:thumb="@drawable/thumb"

How can I set the size of this thumb in dip unit? Because I use a style for seekbar like

<style name="CustomSeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:minHeight">8dip</item>
    <item name="android:maxHeight">8dip</item>
    <item name="android:thumbOffset">8dip</item>
</style> 

and I want to have the thumb with 12dip height and width.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The most flexible way to set thumb size for me is to create layered-drawable with shape as placeholder thumb_image.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape>
            <size
                android:height="40dp"
                android:width="40dp" />

            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
    <item android:drawable="@drawable/scrubber_control_normal_holo"/>

</layer-list>

So basically changing the size of shape will stretch drawable, the shape is transparent so it won't be visible. Also the minimum size of such thumb is size of bitmap.

Here is example of layout:

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:thumb="@drawable/thumb_image" />

<SeekBar
    android:id="@+id/seekBar2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Seek bar with different thumb size


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...