Can't really understand why this is happening. There are lines under all my custom rating bars
Rating Bar
Here is the drawable I am using
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:drawable="#drawable/star_disabled" />
<item android:id="#android:id/secondaryProgress" android:drawable="#drawable/star_disabled" />
<item android:id="#android:id/progress" android:drawable="#drawable/star_enabled" />
Here is the XML
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ratings_bar"
android:stepSize="1"
android:rating="3"
android:progressDrawable="#drawable/ratingbar"
android:numStars="5" />
Does any have a clue on how to fix this? Really not sure what is wrong. The image obviously does contain long streaky marks
I have faced this in the past. Use a layout_margin in the RatingBar. Also, I suspect that the images that you are for the stars may not have any margin themselves and the stars are touching the border of the image. Try to use a slightly smaller star image, with a little white margin (not transparent) in the image itself, to avoid this problem
Related
i tried to create a small rating bar something like this
<RatingBar
android:id="#+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:numStars="5"
android:rating="3.5" />
and its working perfectly ,, now i need to replace star with custom image like this
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar</item>
</style>
ratingbar.xml
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidDomInspection -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background"
android:drawable="#drawable/ic_love_empty" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/ic_love_empty" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/ic_love_fill" />
</layer-list>
the problem here is with the rating bar size ,, its very big and cropped how i can replace #android:style/Widget.RatingBar with this ?android:attr/ratingBarStyleSmall ,, or if any other solution or library its ok for me but i need small
I once had a problem like yours whereby android seems not to consider the resizing of rating bars. All the styles I applied was not small enough to my use case. I ended up using the third party libraries.
The first one or The second one These libraries will help you resizing the rating bars. Because android parent styles of rating bars are hard to resize and do not have default implementation. Happy Coding!
Set your parent style to #style/Widget.AppCompat.RatingBar.Small instead.
I'm trying to create a custom RatingBar for one of my apps. I've followed this tutorial: http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/
The problem is that my RatingBar has always the same size and it's always filled. I try to show different ratings (0,1,2,3,4...) but the rating bar it's the same in all the cases...
I have the ratingBar:
<RatingBar
android:id="#+id/ratingBar"
style="#style/MyRatingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"/>
My Style:
<style name="MyRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_list</item>
<item name="android:minHeight">57dip</item>
<item name="android:maxHeight">57dip</item>
</style>
The layer-list:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/background"
android:drawable="#color/white_text" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#color/white_text" />
<item android:id="#android:id/progress"
android:drawable="#color/red_circle" />
Thank you.
In your <RatingBar> use:
android:numStars to define how many red_circle are used for the full scale of the bar.
android:rating to set the default rating level.
android:stepSize to define the step size of your RatingBar.
<Edit>
I don't believe RatingBar is designed to work using a straight fill color as the progress drawable, which is what you have currently. A color has no dimensions, so drawing 2, 3 or 4 of them has no meaning.
It is designed to work with an image file like the default star png files.
Change your layer-list so the progress drawable points to a Bitmap, or 9Patch, and it works fine. <RatingBar> extends ProgressBar, which uses 9Patchs for the progress drawable.
I am trying to display an int value as a ratingBar. The max value is 5.
This is my XML file:
<RatingBar
android:id="#+id/ratBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
android:numStars="5" />
But if I set the rating with setRating(), android draws a lot of stars. I can't figure out how many because my screen is too small.
Could anybody tell me what's wrong?
I couldn' t understand what exactly your problem is, but using RatingBar in Android applications is quite easy anyway. You need to define your RatingBar in a proper location;
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:numStars="3" />
get a reference to it, within your activity;
private RatingBar rb;
...
this.rb = (RatingBar) findViewById(R.id.ratingBar1);
and start to set values to fill the stars;
this.rb.setRating(2); , this.rb.setRating((float)2.5); etc.
If your screen is too small to display five stars, you can set the number of stars, just as I did above. And you have several options;
1) You can put two ratingbars one under the other one with 3 and the other with 2 stars. When your number exceeds 3, you can continue filling the 2 stars of the bottom ratingbar.
2) If possible, you can set float values instead of integers. So that you can set 1, 1.5, 2, 2.5, 3, 3.5, etc. and you can fill 3 stars for your interval 1-5 after a little algebra.
You need to define your own custom styles to achieve what you want for the RatingBar.
Try out creating the styles and apply that style in your RatingBar view.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="foodRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/food_ratingbar_full</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>
</resources>
<RatingBar android:id="#+id/my_rating_bar"
...
style="#style/foodRatingBar" />
Check out here for more details.
you can try this also
<RatingBar
android:id="#+id/ratingBar"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/artist"
android:layout_below="#+id/artist"
android:numStars="5"
android:rating="2.0"
android:stepSize="1.0" />
This happenswhen the drawable you set in your style for the rating bar has diffent size of png for background, secondary progress and progress.
Change it to something like
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#android:color/transparent" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/star_half" />
<item android:id="#android:id/progress"
android:drawable="#drawable/star_full" />
Spacing between the stars of a rating bar?
I have similar problem but I didn't find solution to make it without changes of images.
Maybe someome faced with such problem and solved it.
Thanks in advance.
Create a custom style that uses your own images with different spacing between them.
Use it in a layout like this:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/RatingBarLarge"/>
Define the style like this:
<style name="RatingBarLarge">
<item name="android:progressDrawable">#drawable/ic_rating_star_large</item>
<item name="android:minHeight">29dp</item>
</style>
Set the minHeight to whatever the height of your drawable is.
Then, define ic_rating_star_large as a layer list like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/ic_rate_star_large_off" />
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/ic_rate_star_large_off" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/ic_rate_star_large_on" />
</layer-list>
Are you using this same kind of code for your rating bar?
// ?android:attr/ratingBarStyle- normal star
// ?android:attr/ratingBarStyleSmall - small star
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#android:drawable/toast_frame">
<RatingBar android:layout_width="wrap_content"
android:layout_height="wrap_content" style="?android:attr/ratingBarStyle"
android:id="#+id/ratingbar_default"
android:layout_marginTop="5dp"
android:layout_marginLeft="-8dp"
/>
</RelativeLayout>
I customize my seekbar like below:
<SeekBar android:id="#+id/progress_seekbar" android:background="#drawable/play_progress_bg"
android:layout_centerHorizontal="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginBottom="-9dp"
android:layout_above="#id/playwidget" android:progressDrawable="#drawable/progress_seekbar_style"
android:thumb="#drawable/thumb_progress" />
in my progress_seekbar_style.xml file, I specified it like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background" android:drawable="#drawable/play_progress_01" />
<item android:id="#android:id/secondaryProgress" android:drawable="#drawable/play_progress_02" />
<item android:id="#android:id/progress" android:drawable="#drawable/play_progress_03"/>
</layer-list>
I want to use this seekbar customization for different screen size; but when it display on the large screen like 600x1024, the seekbar will repeat the picture which I set in "#android:id/background,secondaryProgress/progress " , not stretch my pictures. and I need it automatically stretch my picture to fill parent width. that is what I want, but it just repeat the picture.
can you help? thanks.
Try using nine-patch images. Nine-patch is stretched if you use it for background (even for progress or seek bar).
For testing just rename your image from img.png to img.9.png