开发者

Android seekbar clipped thumb

I ran into some weird problem..I implemented a seekbar with custom thumb..and when I ran my app on HTC Desire, it all works fine..but, when I ran it on Samsung Galaxy, the thumb becomes clipped!

Here are the screenshots..

Desire:

Android seekbar clipped thumb

Samsung Galaxy:

Android seekbar clipped thumb

I would be开发者_开发问答 grateful for any thoughts..tnx

myprogress.xml:

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

<item android:id="@android:id/background">
    <shape>
        <corners
            android:radius="10dp" />
        <gradient
                android:startColor="@color/gray"
                android:centerColor="@color/gray"
                android:centerY="0.75"
                android:endColor="@color/gray"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
        <corners
            android:radius="10dp" />
            <gradient
                    android:startColor="@color/white"
                    android:centerColor="@color/white"
                    android:centerY="0.75"
                    android:endColor="@color/white"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
        <corners
            android:radius="10dp" />
            <gradient
                android:startColor="#FFA500"
                android:centerColor="@color/yellow"
                android:centerY="0.75"
                android:endColor="@color/yellow"
                android:angle="270"
            />
        </shape>
    </clip>
</item>

style:

<style name="mySeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/myprogress</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:minHeight">10dip</item>
    <item name="android:maxHeight">10dip</item>
    <item name="android:thumb">@drawable/thumb</item>
    <item name="android:thumbOffset">4dp</item>
    <item name="android:focusable">true</item>

seekbar xml:

<SeekBar android:id="@+id/player_seek_horizontal"
        android:layout_gravity="center_vertical" 
        android:max="100" 
        android:layout_marginLeft="50dp" 
        android:layout_width="180dp" 
        android:thumb="@drawable/thumb" 
        android:layout_height="wrap_content" 
        style="@style/mySeekBar" 
        android:background="@drawable/background_transparent_rounded" 
        android:paddingRight="4dp" android:paddingLeft="4dp"/>


Adjust the android:paddingLeft, android:paddingRight and android:thumbOffset properties of your SeekBar to achieve desired results.

Padding right and left should be half of thumb's width.


<SeekBar
    ...
    android:paddingLeft="5dp"  
    android:paddingRight="5dp"
    android:thumbOffset="0px" />

It worked for me.


add following attributes to your parent layout

android:clipChildren="false"
android:clipToPadding="false"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜