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.
Related
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.+'
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 custom button with a state list drawable that has a tight layout with very little padding. This button looks great on MDPI and HDPI devices, but padding is all wrong on my Motorola Xoom (ICS, MDPI device). Modifying the 'padding' and 'margin' attributes does nothing.
Anyone have any suggestions on what may be causing the unnecessary padding? I'm fairly confident that both the state list drawable and the 9patch drawables are fine (they render perfectly on other MDPI devices).
Attached is an example of what the final product looks like - green border denotes its ideal appearance (and the way the button looks on other devices); magenta border denotes the appearance on the Xoom.
I encountered some situation when developing a appwidget. I added a button and try to trim all paddings of it to make it small but failed, there are always a top padding and a bottom padding. I believe it's a constraint of Android system, so that all buttons in appwidget are large enough for end users to tap. However sometimes we insist small buttons due to boss... As the workaround Melllvar indicated, I used a focusable, clickable TextView instead of a Button, it works as expected.
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.
I'm developing an Android app targeting Android 2.3 (API9).
I want to resize the height of a simple EditText but when I set android:layout_height="10pt" the border of the EditText becomes dislocated.
The problem is shown here
I tried layout_height, height, textsize.. pt, px, sp... but the same problem.
I haven't tried the application on real device yet.
What layout contains the EdiText? You should never use exact pixel sizes when configuring items in Android, since your layout needs to work properly at many different screen sizes and densities. (See supporting multiple screens for details).
If you really want a specific size, us dp for density independent pixels. It should work to set the layout_height="10dp" However, that won't increase the size of the text within the EditText. You need to use textSize for that. You are probably better off setting textSize and setting the layout_height="wrap_content".
See this similar question about the extra line. It looks like setting a background color might fix that.
I have been having the same sort of problem (and it's a real pain). With some experimentation I have found that if you use "dp" and apply this rule of thumb, it should work for EditText fields.
textSize x 3= layout_height
I say rule of thumb because the minimum height before the field "breaks" again is about 29dp. So, for example if you have textSize="10dp", then layout_height="30dp", or textSize="12dp", then layout_height="36dp". You can have smaller textSizes, but it becomes illegible lower than 9dp. I found this works well in relative_layouts with default fonts. Good luck!