Android: Custom Drawable in a SeekBar widget is drawing aliased images

Problem is when I am using a custom progressDrawable in a SeekBar widget (perhaps incorrectly) it is rendered in a very aliased/ugly/low quality form. I have set “drawingCacheQuality” to high and there is no difference. Anyone have any ideas?

Am developing on a Nexus One (OS 2.2.1) with target build for project as API 1.5 (though I would hope that shouldn’t matter).

Here is a sample of what it looks like:

alt text

My aim is to create a simple nifty visual switch with two states (on and off), and a slider to move between them. I didn’t really see a better widget for this and practically everything is done for me with SeekBar. If someone has a better idea which doesn’t involve rewriting tons of boiler plate code that would be nice. It just seems like this should really be doable with minimal effort somehow working with or extending SeekBar. I’m at a bit of a loss where to start though.

I’m guessing one idea would be to just overlay my on_off image onto the ShapeDrawable and use that as the background (and “@android:color/transparent” for progressDrawable), but I’m not too familiar with how to do that…

Basic code for a new actvitiy

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        seek = (SeekBar)findViewById(R.id.seek);
        seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
            }
            public void onStartTrackingTouch(SeekBar seekBar) { 
            }
            public void onStopTrackingTouch(SeekBar seekBar) {
                if (seek.getProgress() < seek.getMax() / 2.0)
                    seek.setProgress(0);
                else
                    seek.setProgress(seek.getMax());
            }
        });
    }

main.xml defining the SeekBar

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">
    <SeekBar android:id="@+id/seek"
                android:layout_alignParentTop="true" 
                android:layout_centerHorizontal="true"
                android:layout_height="wrap_content" android:layout_width="200dip" 
                android:background="@drawable/background"
                android:padding="4dip" 
                android:drawingCacheQuality="high" 
                android:progressDrawable="@drawable/slider_on_off"  
                android:progress="99" android:max="99" 
                android:maxHeight="100dip"
                android:thumb="@drawable/slider_box"
                android:thumbOffset="0dip"
                />
</RelativeLayout>

background.xml Background of seekbar

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" 
    android:useLevel="false" >
    <corners 
        android:radius="4dip" />
    <solid
        android:color="#FF282828" />
</shape>

Answer

The drawing cache quality has no relation with what you are trying to do. Make sure that you put your images in the res/drawable-hdpi folder.