Android rating baar not showing properly - android

Ratingbar star not showing properly.
i don't know what i am doing wrong with it.
when i used custom style then a single star is showing only and its length is equal to 5star.
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-15dp"
android:stepSize="1"
android:numStars="5"
style="#style/customRatingBar" />
Style is:
<style name="customRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/manual_ratingbar</item>
<item name="android:minHeight">32dip</item>
<item name="android:maxHeight">32dip</item>
</style>
manual_ratingbar file:
<?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/ic_star_unselect" />
<item android:id="#android:id/progress" android:drawable="#drawable/ic_star_select" />
</layer-list>
it looks like:
and when i changed the Ratingbar style to
style="?attr/ratingBarStyleIndicator"
then there is extra star visible in background.
what should i do?

#chandan you can resolve this issue by adding this on RatingBar Layout android:indeterminate="false"

Related

rating bar becomes to large and is cut-off when adding custom images in android

I followed an answer on stack overflow to adding a custom rating bar to an android project, here it is: https://stackoverflow.com/a/32828726/5909396
Just in case I am posting my code.
First I created ratingBar.xml in drawable folder:
<?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/ratingbar_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/ratingbar_empty" />
<item android:id="#android:id/progress"
android:drawable="#drawable/ratingbar_filled" />
Then I created ratingbar_empty.xml and ratingbar_filled.xml also in drawable folder:
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_emptyStar" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_emptyStar" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_emptyStar" />
<item android:drawable="#drawable/ic_emptyStar" />
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_fullStar" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_fullStar" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/ic_fullStar" />
<item android:drawable="#drawable/ic_fullStar" />
And then I created the custom style in styles.xml
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar</item>
<item name="android:minHeight">50dp</item>
<item name="android:maxHeight">50dp</item>
</style>
And finally I added a ratingBar to layout. The way I structured it is the rating bar is inside a relative layout and there is a textview inside the relative layout as well that is on top of the rating bar (The text view shows if there is no rating);
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="vertical"
android:layout_gravity="center">
<RatingBar
android:id="#+id/ratingRestaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/CustomRatingBar"
android:numStars="5"
android:stepSize="0.1"
android:isIndicator="true"
android:max="5"
android:progress="3"
android:layout_centerVertical="true"
android:progressTint="#ffe4b331" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No rating available"
android:textColor="#android:color/white"
android:textSize="11dp"
android:id="#+id/textViewNoRatingAvailable" />
</RelativeLayout>
When I run the application on the simulator, the stars are really large and are cut-off like below:
There are supposed to be five stars. How can i fix this problem?
I made a library with a customizable rating bar. You can set full and empty icon and their size. I hope this helps you.
This is an example of the usage, is very simple:
<com.kabuki5.logicalratingbar.CustomRatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:clickable="true"
app:iconSize="58dp"
app:imageEmpty="#drawable/ic_heart_empty"
app:imageFull="#drawable/ic_heart_full"
app:initRating="5"
app:maxItems="5" />
Also you can set a listener to get on change value callback.
Logical Rating Bar
set
android:layout_width="wrap_content"
android:layout_height="0dp"

RatingBar with small white stars

The following is the xml for my rating bar.
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:isIndicator="true"
android:stepSize="0.5"
android:rating="4.5"/>
I am happy with its size but I would like to stars to be white on grey (white for filled and grey for empty).
I am looking at this tutorial (http://www.materialdoc.com/rating-bar/) but I am not sure how to adapt the style to suit the small appearance.
You can try drawable
<?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_off" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/star_off" />
<item android:id="#android:id/progress"
android:drawable="#drawable/star_on" />
</layer-list>
<RatingBar
android:id="#+id/ratingBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/custom_ratingbar_selector"
android:isIndicator="true"
android:stepSize="0.5"
android:rating="4.5" />
you can use progressTint for this purpose
<RatingBar
android:id="#+id/vendorRatingBarValue"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/reviewerName"
android:clickable="false"
android:gravity="left|center"
android:isIndicator="true"
android:numStars="5"
android:progressTint="#color/white"
android:transformPivotX="0dp"
/>
you would need to use the attributes
android:backgroundTint="#color/grey"
android:progressTint="#color/white"
so..
<RatingBar
android:id="#+id/rb_doctor"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#color/grey"
android:numStars="5"
android:progressTint="#color/white"
android:rating="0"
android:secondaryProgressTint="#color/white"
android:stepSize="1.0"
/>
This is simple example of RatingBar.
Custom white and gray star can possible with custom theme for this and specify small size so size of rating bar star will be same as default small size theme.
You have to create drawable for custom rating bar and make sure about the size of rating bar because here height of rating bar matters a lot.i mean if your star image is size of 13dp height and rating bar is 17dp height than it will stretch the rating bar so make sure about height.
Here is simple example of how can create custom selector for rating bar.
Star Drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:state_focused="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:state_selected="true" android:state_window_focused="true" android:drawable="#drawable/ic_star_empty_small" />
<item android:drawable="#drawable/ic_star_empty_small" />
</selector>
Style for rating bar
<style name="foodRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/inf_full_ratingbar</item>
<item name="android:minHeight">20dip</item>
<item name="android:width">20dip</item>
<item name="android:height">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
And than use custom style for rating bar like:
<RatingBar
android:id="#+id/ratingBarFlight"
style="#style/StarRatingBar"
android:layout_width="wrap_content"
android:layout_height="#dimen/rating_bar_height"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/library_screen" />

Android: Color of stars in RatingBar, that already uses style

I want to change colour of RatingBar stars in every mode(highlighted, notHighlited, progress), but I already use style Widget.AppCompat.RatingBar.
I don't want to change style cause, I like star shapes and staff, I only want to change star colors, Is it possible?
Here's my code:
<RatingBar
android:id="#+id/ratingBar"
style="#style/Widget.AppCompat.RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:layout_gravity="center_horizontal"
android:rating="0.0" />
Use styles:
<?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/background" />
<item android:id="#android:id/secondaryProgress" android:drawable="#drawable/secondary_progress" />
<item android:id="#android:id/progress" android:drawable="#drawable/progress" />
</layer-list>
You can use this style following way. Add this line to the RatingBar:
android:progressDrawable="#drawable/rating"

How to apply RatingBar border without using an image?

I wanted to create a RatingBar that does not use an image to have a border. But I can't seem to get it right.
Here's what I wanted it to look like:
Here's what I got (filled - half empty - empty):
Here's my layout:
<RatingBar
android:id="#+id/ratingbar_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numStars="5"
android:rating="2.5"
android:stepSize="0.5"
android:scaleX="3.5"
android:scaleY="3.5"
style="?android:attr/ratingBarStyleIndicator"
android:isIndicator="false"
android:progressTint="#color/star"
android:progressBackgroundTint="#color/star_border"
android:secondaryProgressTint="#color/star_partially_empty"
android:backgroundTint="#color/star_partially_empty"
/>
Maybe any of these additional libraries: http://android-arsenal.com/tag/84
would do a disired work for you. Notice, that some of these doesn't use image.
Hope it help
Okay, so I used a custom drawable layer-list and Android will be the one to do the rest.
My RatingBar:
<RatingBar
android:id="#+id/ratingbar_rate"
style="#style/rateUsBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="0"
android:stepSize="1"
android:layout_gravity="center"
/>
In styles.xml:
<resources>
...
...
<style name="rateUsBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_stars</item>
<item name="android:minHeight">#dimen/rate_us_star_minheight</item>
<item name="android:maxHeight">#dimen/rate_us_star_maxheight</item>
</style>
</resources>
In rating_stars.xml:
<?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/rate_empty" /> //gray star for empty
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rate_empty" /> //gray star for empty
<item
android:id="#android:id/progress"
android:drawable="#drawable/rate_filled" /> //yellow star for filled
</layer-list>
In dimens.xml:
<resources>
...
...
<dimen name="rate_us_star_minheight"> <!--height of your image--> </dimen>
<dimen name="rate_us_star_maxheight"> <!--height of your image--> </dimen>
</resources>
And that's it!

How to set custom ratingbar for different screens in android

Xml file:
<RatingBar
android:id="#+id/row_item_rbRatingAvg"
style="#style/CustomRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:isIndicator="true" />
Style file:
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingstars</item>
<item name="android:minHeight">#dimen/rating_bar_height</item>
<item name="android:maxHeight">#dimen/rating_bar_height</item>
</style>
ratingstars.xml
<?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_icon_a" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/star_icon_a" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/star_icon" />
</layer-list>
dimens.xml
<dimen name="rating_bar_height">38px</dimen>
above files i used for set my custom ratingbar. i have also different size images for star_icon_a and star_icon. but still not working. in some devices, image get scaled and in some device image get cut. i dont know how to make for all screen sizes.
below is sample of drawable-xxhdpi size.

Categories

Resources