Marche101
Marche101

Reputation: 825

Create Custom Seekbar Programmatically (No XML)

Currently I am trying to create a custom Seekbar without using xml as the images for the background and progress bar need to be changed. This is what I have at the moment:

Drawable drawable = new BitmapDrawable(appState.images.get(Integer.parseInt(image)));   
this.setBackgroundDrawable(drawable);

Drawable drawable2 = new BitmapDrawable(appState.images.get(Integer.parseInt(image_a)));    
this.setProgressDrawable(drawable2);

this.setProgress(0);

But the progressDrawable is just set to the entire size of Seekbar and when I move the thumb from side to side nothing happens. Does anybody have any ideas as I am completely stumped.

Upvotes: 1

Views: 5570

Answers (1)

anthropomo
anthropomo

Reputation: 4120

So this previous answer does the trick for you:

Changing the size of the seekbar programmatically but cant get the thumb to be larger than the bar

From the original asker:

In the end I am using this code:

public void setSeekBarImages(){
    Drawable drawable = new
             BitmapDrawable(appState.images.get(Integer.parseInt(image_a)));
    ClipDrawable clip = new ClipDrawable(drawable,
             Gravity.LEFT,ClipDrawable.HORIZONTAL);
    Drawable drawable2 = new
             BitmapDrawable(appState.images.get(Integer.parseInt(image))); 
    InsetDrawable d1= new InsetDrawable(drawable2,5,5,5,5);
    //the padding u want to use
    setThumb(null);
    LayerDrawable mylayer = new LayerDrawable(new Drawable[]{d1,clip});
    setProgressDrawable(mylayer);
    setProgress(0);
}

Upvotes: 4

Related Questions