Android: custom Drawable in SeekBar widget draws anti-aliased images

The problem is that I am using custom progressDrawable in SeekBar widgets (maybe wrong), it displays on the form with very smooth / ugly / low quality. I set "drawingCacheQuality" to a high level and there is no difference. Does anyone have any ideas?

Developed on Nexus One (OS 2.2.1) with a target build for the project as API 1.5 (although I hope it doesn't matter).

Here is an example of what it looks like:

alt text

My goal is to create a simple excellent visual switch with two states (on and off) and a slider for moving between them. I really have not seen a better widget for this, and almost everything is done for me with SeekBar. If someone has a better idea that does not require rewriting a ton of code plate with a bowler, that would be nice. It seems like this really should be doable with minimal effort, somehow working with or expanding the SeekBar. I am at a loss where to start.

I guess one idea is to simply overlay my on_off image on a ShapeDrawable and use it as a background (and "@android: color / transparency" for progressDrawable), but I'm not too familiar with how to do this. ..

The base code for the 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 a 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 arrows

<?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>
+1
2

, . , res/drawable-hdpi.

+3

Source: https://habr.com/ru/post/1787402/


All Articles