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.
Related
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 would like to develop a layout below. I am really confuse related to that. I used RelativeLayout, FrameLayout to develop this. But I am not getting perfect output. As per below image, the Dark Gray color is overlap the light Gray layout. If I used Relative layout then dark Gray will be in the light Gray area. And if I used FrameLayout then the other controls of light Gray will not set perfectly.
Please guide me the right path. I am stuck in this layout. Thanks in advance.
According to your figure, If all widgets need to show without scrolling vertically , you can have vertical linear-layout here,
TextView
Button,
ImageView
List view with defined height
Other widgets
I have a very simple question.
I have been asked by my company to make the actionbar just a simple imageview. So no icon, no title and no buttons at all. I've created a custom actionbar, and the imageview is up there just fine. I have attached a link to an image of my layout, and the emulator on the right. They want the imageview to be like it is in the layout. But in the emulator it comes up small.
My question is simply: is there a way I can make the imageview fit like it is in the layout there, and of course have it fit for different devices too - or, must the graphic designer simply create a banner that fits the size of an actionbar. If so, I looked at android's iconography and saw the height should be 48dp. but what about the width? And won't different devices have different width? Or will i be able to make sure it is stretched across the whole width of the screen. I've tried match parent in my xml but of course it won't do anything now because it doesn't want to stretch the height of the actionbar.
Thanks alot
https://www.dropbox.com/s/1tek8ptar3j76d4/Screenshot%202015-02-27%2009.55.30.png?dl=0
Get your graphic designer make you a 9 patch png that will expand in the middle while keeping its proportions then simply add this line of code:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.your_nine_patch_png));
More on nine patch images here: http://developer.android.com/tools/help/draw9patch.html
Here is the trick!
yourImageView.setGravity(Gravity.FILL_HORIZONTAL);
Happy coding! ;D
I'm trying to make an android app. But I'm having many troubles with the design. I want to make a navigaton bar with a height of 48 dp on every screen. I know which height in px I have to use but I don't understand which width because every screen has another and it dosen't scale right. I just want a navigaton bar in one color with a height of 48dp and a witdh which scales to the screen so that it is from the left all way to the right with a continious height of 48dp. I hope you understand my problem if not please ask. Thanks for your time!
FOR PEOPLE WITH SAME PROBLEM:
android:scaleType="fitXY"
The accepted answer is deprecated. Please use match_parent instead of fill_parent
There is one more attribute
android:gravity="fill_horizontal"
(Grow the horizontal size of the object if needed so it completely fills its container.)
FOR HELP
Try using android:layout_width="fill_parent".