Android: SeekBar with custom drawable
Android: SeekBar with custom drawable
I have SeekBar with custom drawable. Progress element is not rendered from left side exactly but it is moved to right. How can I avoid this?
seekbar.xml
-
seekbar_background.xml
seekbar_progress.xml
EDIT:
As mentioned in comments if there will be both widths same problem disappear. But I need make it with two different widths through drawable is it possible? Maybe with different shapes not just lines?
Answer by Mina Fawzy for Android: SeekBar with custom drawable
As it appear the issue in progress I think they both should be the same width
but you in progress make width = 4 android:width="4dp"
and seekbar width = 2 android:width="2dp"
just match them to be 2 or 4 dont use different values
Answer by David Medenjak for Android: SeekBar with custom drawable
I can not explain why this is an issue when drawing strokes, I think it has something to do with the strokes width, but I did not yet find the source to verify.
Fixing the Overlay
To remove the issue at hand, you can just set an inset
on your left side. A value of 1dp
or 2dp
both work and the seekbar will be drawn properly.
Note: Using this approach there should be no risk that the background could be too short and not visible with low progress values, since the thumb would overlay and hide it in any case.
-
-
Answer by Arnab Jain for Android: SeekBar with custom drawable
Try using a .9.png drawable of width 4dp (converted to px) .
Keep 1 dp at top and bottom transparent.
And add colour to the center 2 dp of your choice for the background.
This way both background and progress will be of same width but the background will look thinner than progress bar.
Answer by Sudheer Naga for Android: SeekBar with custom drawable
Try like this using android:layout_marginLeft="-3dp"
or -2dp
`
Answer by Sanjeet Ajnabee for Android: SeekBar with custom drawable
Observation
When you create a line using shape drawable it leaves the left and right padding (from the view in which this drawable is being used.)equal to the half of its stroke width.
Workaround
You need to wrap your progress_background with an inset drawable and then set it as progress background. The inset can be like the following-
inset_seekbar_background.xml
and your final seekbar.xml will be like-
-
Alternates
1.You can use an 9 path image for line as it is done in the default material design-
-
-
-
-
2.You can set the theme to your view with different color in android style as-
Here I have used all there options for Seekbars-
Answer by Jawad Le Wywadi for Android: SeekBar with custom drawable
If your choices of color has a limit and is predefined. You can try to add XML files with Seekbars using different themes.
Something like this:
themed_seekbar_one.xml
themed_seekbar_two.xml
You can then inflate does views programatically like this:
SeekBar seekbar = (SeekBar)getLayoutInflater().inflate(R.layout.themed_seekbar_xxx, null);
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment