Currently I am attempting to change the drawable image of the Thumb of a seekbar in android. In the onCreate() method I am able to effectively change the thumb using the following
mSeekBar.setThumb(myDrawable);
However, after the onCreate method is called, I attempt to change it again using a different drawable with the same method and the thumb disappears. The api description is 'Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.' Does this mean that the image will be drawn off screen (if i 'fill_parent' with my seekbar)? I have tried changing the offset with no avail, has anyone else run into this issue? Or know how to change the thumb image while the progress is changing?
I also should mention that I am setting my background drawable for the seekbar to a blank xml file (i.e. to not have a background image).
One thing that has partially worked for me is to use the setBounds method however the problem I have run into is that in my app it resets the position of the thumb drawable back to the beginning of the line. I don't know if this is related to how my code works or if it happens no matter how it is implemented.
Drawable myThumb = getResources().getDrawable(R.drawable.slider_button);
myThumb.setBounds(new Rect(0, 0, myThumb.getIntrinsicWidth(),myThumb.getIntrinsicHeight()));
skbr.setThumb(myThumb);
Related
I have a SeekBar that I'm trying to implement custom styling on. The edges of my progressDrawable have rounded corners which I think looks great, however when i drag the thumb to the edges it looks strange.
This is how the SeekBar looks when I use an "in the middle" progress value like 80.
And this is how the start and end look when I use a progress value of 0 or 100 respectively. You can see how the rounded corners look strange due to the way the thumb goes all the way to the end of the SeekBar.
I'm looking for a way to get the thumb to STOP at around 16dp before the end of the SeekBar, but for the progressDrawable to still fill it in as if it had gone to 100.
I also just noticed that the thumb seems to cut off half way through it's drawable. That is not related to what I'm asking, so I'm trying to avoid any confusion there.
I have a problem with seekbars. They work without issues until I try and do the following:
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.seek_bar));
I even tried using a color only instead of a drawable resource. Same issue. The problem is when I do set the drawable, I see that the Seekbar drawable is a bit shorter (from start and end) and the thumb icon can go beyond it.
Also, I have noticed that the thumb icon itself has a white background surrounding it (not transparent). I even tried setting a vector drawable for the thumb, and the thumb went beyond the boundaries of seekbar (part of the thumb was hidden).
Could someone explain this behavior. I have tried searching for around three hours now without luck. I even tried the solution from:
How to set Android SeekBar progress drawable programatically
Which has the same issue for me.
Thank you.
To get rid of the non-transparent background I have used:
seekBar.setSplitTrack(false);
To make the thumb not go beyond the boundaries, I have shrunk the thumb. It is not perfect but it works.
Why the standard seekbar in Android 2.1 or other version looks so odd. I mean the Thumb image begins outside the container. Am I doing something wrong or this is a normal behavior. How to correct this behavior ?
It is the default thumb image. You can set the thumb image of seekbar. create a small image which you like to set as thumb image. using the following code
android:thumb="#drawable/music_player_playerhead"
I'm using a layer-drawable and inside it I have one BitmapDrawable that repeats only horizontally. But I need to add borders for this drawable.
But I didn't find any solution for this!
I tried to create a ShapeDrawable and set my BitmapDrawable as background of my ShapeDrawable, but it's not possible.
I tried to find a method that add borders for my ShapeDrawable, but I didn't find it.
I also added 2 other images, that would be the box_top_left and box_top_right.
With this idea, I only need now to make it appear in this order:
box_top_left, box_repeat, box_top_right.
But i'm also having trouble to do this!
I've found a several ways to change a drawable's padding in my xml but not during the execution. I can't just set it on my xml because I don't know the total width.
And I didn't find any way to make my drawable the exactly width of my image.
Can somebody help me, plz?
I'll post some images to help you to understand what I want to do.
The first image is how it should be:
Inside my Dialog, at the top, above the text "Acesso ao sistema" I have my image that sould repeat.
I used a layer-drawable for my Dialog's background with a item that is the shape for my dialog and another item that should have my BitmapDrawable repeating only horizontally.
This second image is only missing to add my box_top_left and box_top_right.
This third image is what happens when I don't use borders:
And the last image is third image expanded for you to see the problem:
Thanks for your attention.
I think using a nine-patch for this will make your life a lot easier.
I think you can try Layer List, and define two items. One item is a shape which you can add stroke to be the border, and the other one is a bitmap which you can set tileMode to be "repeat" to repeat.
I used this method to implement my task. And I ran into one problem which already was fixed.The bug is that the repeat area seems have some lines between images.This may be caused by the shape having default black background. So I set the shape item's color to transparent.
Hope this will work for ya~~
I have set negative paddings on my custom seekbar so that the round thumb image can go outside the bar, but the thumb isn't rendered out there, is there anyway to force the thumb to be drawn outside those bounds?
Sorry guys, I'm new to Android development, and have been tasked with fixing an existing application. The problem is that we have a custom rounded looking track bar, which consists of two rounded 'end cap' images and a 1 px background that is tiled to create the seekbar. As far as I can tell there was never one image that could be set as the background of a normal SeekBar, which is why a custom one was created.
The thumb is a circle and needs to 'fit' into the end caps - the three pieces of the bar are in a relative layout. Right now I'm kind of unclear as to how the 1 px background png gets stretched as the seekbar bg, otherwise I would try to tack on the two endcaps onto that drawable some how ... ?
Please let me know if this was unclear and I'll try to post any followup info. Thanks in advance for any advice!!
Oh, I'm using Android 2.1 if that's relevant to anyone's interests :)
This is what it looks like when the thumb all the way over - outside of the seekbar. Ideally what I need is for the thumb to be shown as 'inside' the endcap image :-/
I was having the same problem, my thumb is very big length wise and it kept being cut off. Make sure that you set the offset property AFTER you set the drawable for your thumb, like this:
seek.setThumb(Main.app.getResources().getDrawable(R.drawable.thumb));
seek.setThumbOffset(15);
This will set the correct offset when your thumb is very long.
Try to change the thumb offset property, after that it will not go off from the seek bar
I just ran into this issue. I was able to get satisfactory results by using android:paddingLeft and android:paddingRight within the XML.