I have a RatingBar component in the application for which I have the following configuration:
android:numStars="5"
android:stepSize="1.0"
The problem is as soon as the touch crosses one pixel from the section of the next star, the next star is highlighted too. Is there a way to wait until the finger touch is more area from the next star and only then highlight it.
NOTE: I don't use PNGs for the stars.
In case your are willing to try a RatingBar different from the stock one, you might wanna try a library I made: SimpleRatingBar.
It solves the problem that you mention by drawing the fill only when touch event is greater or equal than stepSize / 4. This makes the behaviour a bit more smooth and less "jumpy".
It features:
Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
Arbitrary number of stars.
Arbitrary step size.
Size of stars can be controlled exactly or by setting a maximum size.
Customizable colors in normal state (border, fill and background of stars and rating bar).
Customizable colors in pressed state (border, fill and background of stars and rating bar).
Customizable size separation between stars.
Customizable border width of stars.
Customizable stars corner radius.
Allows to set OnRatingBarChangeListener and OnClickListener
Stars fill can be set to start from left to right or from right to left (RTL language support).
AnimationBuilder integrated in the view to set rating programatically with animation.
Here is a preview of it.
You can find it in jcenter, Maven Central and JitPack. So in your build.gradle file just add to your dependencies:
compile 'com.iarcuschin:simpleratingbar:0.1.+'
Related
I want to understand what is this color change means?
this is only an example..i want to understand what is 9 patch for and how it works
i changed my png to 9.png and after i make some changes (this is NOT that image this only for reference )
i notice that some color is changed in images
i just want to know how to understand which color for what ?
and how to use it ?
The black lines at the edges of the image act as a guide to the nine-patch to determine which parts of the image are scalable, and which parts need to be kept exact. The black lines on the bottom and right edge represent the fill area, basically the total bounds from which scalable areas can be selected. This is typically the length of the flat edge before the corners begin.
The black lines on the top and left edges represent the scalable area. When the image is resized, these lines show where the image can be safely expanded and contracted while still maintaining its appearance. You'll notice that in your example image there is a small gap in the left edge - this is so the speech bubble spike is not expanded along with the rest of the bubble.
And to answer your question on the colours, green zones show areas of the image that can resized in one dimension only (only height or width), while pink areas show parts of the image where both dimensions can be resized. The purple areas in the right-hand preview show the total space expansion.
Radley Marx explains things a little better in this blog post.
Is there a way to change RatingBar Widget size , programmatically without using xml styles?
I know we can customize size of RatingBar using xml styles , but it is still not generic enough , i seem to encounter some of good github libraries that achieve this goal but they are offering it for cost of API 15+ , my minSDK is 10 , so can anyone help identify solution to :
Reduce size of ratingBar widget programmatically under api 10 ?
This a long shot, but:
If you are using only stars (no custom shapes).
You are willing to use API 11+.
I made a library which might help you: SimpleRatingBar.
It features:
Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
Arbitrary number of stars.
Arbitrary step size.
Size of stars can be controlled exactly or by setting a maximum size.
Customizable colors in normal state (border, fill and background of stars and rating bar).
Customizable colors in pressed state (border, fill and background of stars and rating bar).
Customizable size separation between stars.
Customizable border width of stars.
Customizable stars corner radius.
Allows to set OnRatingBarChangeListener
Stars fill can be set to start from left to right or from right to left (RTL language support).
AnimationBuilder integrated in the view to set rating programatically with animation.
Here is a preview of it.
To change the width you can change it as you would do with any other view (more info). For example:
ratingBar.getLayoutParams().width = newWidth;
ratingBar.invalidate();
You can find it either in jcenter or in Maven Central. So in your build.gradle file just add to your dependencies:
compile 'com.iarcuschin:simpleratingbar:0.1.+'
I hope it's useful.
I have a standard implementation of a RatingBar. 5 stars, 1 in stepsize.
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1"
android:progressDrawable="#drawable/dark"
android:rating="#={viewModel.rating}"
/>
I have noticed that I have a problem on some devices, or brands actually: Samsung, Nexus, maybe more... But I don't have the issue on Sony and LG devices, maybe more here as well.
The problem is that the precision when selecting a value is really bad. It seems like if I pass the middle of the rating-drawable it will fill the following "star". It seems to be the threshold for those devices and that's just the way it is. They way the LG and Sony behaves is that when you pass half the distance between two "stars", then it fills in the next star.
So, is there anything I can do to prevent this?
As far as I know, there is no way around it.
I'm the creator of a library which provides an alternative to Android's default RatingBar: SimpleRatingBar, and we discussed this behaviour in one issue.
In the library, we modified this behaviour so one star will be selected only if at least 1/4 of it is pressed. I believe this improves the overall experience when using it.
If you want to, you can give it a try.
It features:
Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
Arbitrary number of stars.
Arbitrary step size.
Size of stars can be controlled exactly or by setting a maximum size.
Customizable colors in normal state (border, fill and background of stars and rating bar).
Customizable colors in pressed state (border, fill and background of stars and rating bar).
Customizable size separation between stars.
Customizable border width of stars.
Customizable stars corner radius.
Allows to set OnRatingBarChangeListener
Stars fill can be set to start from left to right or from right to left (RTL language support).
AnimationBuilder integrated in the view to set rating programatically with animation.
Here is a preview of it
You can find it either in jcenter or in Maven Central. So in your build.gradle file just add to your dependencies:
compile 'com.iarcuschin:simpleratingbar:0.1.+'
I hope it's useful.
I'm attempting to use a different "homeAsUpIndicator" graphic on the action bar, and I'm running into some margin issues with the edge of the screen and the graphic.
Using the "android:homeAsUpIndicator" attribute with a value of #drawable/my_graphic in the styles.xml for the project, I've managed to change the indicator to a custom graphic. That graphic has been designed with a 0dp left margin in mind - as in the left edge of the graphic should go all the way to the left edge of the screen. Instead, I'm getting a 6 pixel margin on both the top and the left side the image.
I've tried setting the margins and padding in my styles.xml, but either that doesn't work or I've applied it to the wrong resource. Also, I tried setting the actionbar background to a 9-patch graphic and let the standard indicator graphic (the "<" in Honeycomb 3.1) float on top of it...that didn't work either, as it just pushed the indicator graphic to the right of the fixed pixels of the background. It only overlayed the pixels that were identified as the stretch pixels in the 9-patch.
Is there a way to remove the 6-pixel padding/margin from the actionbar so the indicator graphic is flush with the left side of the screen? Any examples or leads would be greatly appreciated!
Thank you
Have you provided drawables for different screen sizes / resolutions / densities?
Though they should resize automatically.
See here for icon design of action bar :
http://developer.android.com/guide/practices/ui_guidelines/icon_design_action_bar.html
Also you can check the standard icons being used in your sdk folder and adapt yours to those:
the path is:
ANDROID_SDK/platforms/android-XX/data/res/drawable-XXX
https://stackoverflow.com/questions/8179653/where-can-i-find-standarts-icons-for-actionbar
Otherwise check also here:
How to remove the margin between the app icon and the edge of the screen on the ActionBar?
Also you could use a custom action bar:
Custom title bar without padding (Android)
Hi I am using Rating Bar in my App. When I try it in emulator the rating bar is fully visible. (i.e) I am able to see all the five stars, but when I try it in my droid mobile, I am able to see only four stars. Can anyone suggest me a solution for this.
This can be layout issue. In droid mobile if your layout is not able to stretch properly , and you have specified certain width to rating bar, stars(layout) gets truncated. Arrange layouts using layout weights, that might solve your problem.
Do you have any padding on the RatingBar element? I just had a similar clipping issue when layout_width of my RatingBar was set to wrap_content and I had paddin_left and padding_right defined.
Removing the padding removed the clipping
The problem seemed to be because of a totally different situation.
The Default star of the Rating Bar doesn't reduce their size to adjust the layout. What ever is the screen size it has the same size(Big, small etc). So if we set the Star size to big, it will just make the star to hide from the layout. So the best solution is to make the layout size enough to fit the number of stars you are about to provide.
If not provide small style star to your Rating Bar if your layout can't accomadate big star style.