Pergunta

I have the following code for my seek bar

<SeekBar
    android:id="@+id/sbCardSpeed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginRight="5dp"
    android:max="100"
    android:progress="50"
    android:secondaryProgress="0"
    android:progressDrawable="@drawable/seekbar_progress"
    android:thumb="@drawable/seek_thumb" />

seek_thumb is a 9 patch image file called seek_thumb.9.png. The problem that this drawable is not recognized and the thumb is not shown. However when I remove the .9. from the file name then my thumb is shown with the black guide lines

Any idea why or how to fix this?

Foi útil?

Solução

Nine-patch PNG files are almost exclusively used for background of widgets, such as the background of a Button. The SeekBar thumb is probably not being drawn as a background. I would have expected your nine-patch PNG to still work, but apparently it doesn't.

The standard SeekBar thumb image is not a nine-patch, as it does not need to be resized the way a Button background does. Hence, I'd stick with standard PNG files for the different states, and reference them from an appropriate StateListDrawable pointing to your PNG files.

You can find the stock drawables in $SDK/platforms/$VERSION/data/res/, where $SDK is wherever your Android SDK is installed on your development machine and $VERSION is some API level. The standard StateListDrawable which is the actual SeekBar thumb should be in drawable/, while the PNGs used by that StateListDrawable are in the various density-dependent directories (e.g., drawable-hdpi/) as seek_thumb_normal.png, seek_thumb_pressed.png, and seek_thumb_selected.png.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top