Changing RatingBar Size Programmatically? - android

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.

Related

Android RatingBar highlights the star sooner than expected

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.+'

The Android RatingBar has "bad" threshold for certain devices, fix?

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.

DP and Scaling with devices and AutoLayout iOS swift

I am migrating from Android to iOS (Swift). In Android UI elements are scaled up or down (height and width using "dp", layout_weight e.t.c) according to device size.
However I find this VERY difficult to achieve with Auto Layout's constraints, I want the elements in my UI to scale according to device size.
For example, in the shared image below, asides the compression of images to fit the screen width, every UI element has the same size, only looks like UI elements have been duplicated with same specs on all screens
This might help others in their migration from Android to Swift
(I only pinned the width of the 2 ugly ImageViews below)
P.S: This is what I'm trying to replicate guys, this view to fit properly on all screens. Sorry for the blur, I'm not in charge of this project
There's a zen to the AutoLayout. Let me see if I can give you some direction.
You'll want to test every UI on the smallest simulator available (iPhone 4S). This will let you know if you need to adjust your elements' minimum size.
Now for a top-to-bottom review of your UI posted:
"Profile" looks fine
To make the top-left and top-right boxes resize with screen size, you'll
want to give a constraint to the superview on left and right sides respectively. Then you'll want to make a horizontal constraint between the two (to maintain a space between them. Then you'll want to set them to equal widths. You can also set aspect ratio constraints for each one.
Your forms look fine. I can give more guidance here if the look you're after doesn't match the image you posted.
For the views below the form, you'll probably want to follow #2 above.
As for the height issue, set a constraint from your bottom view to the superview's bottom. There might be crowding, interface builder might yell. Chances are, you'll need to set the horizontal spacing constraints from = to >=.

Honeycomb actionbar and margins

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)

Android RatingBar problem in device

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.

Categories

Resources