Custom Android Rating Bar stretching image - android

I'm having a little problem when using a custom rating bar style. I've read other topics on this, but the proposed solutions/answers are not solving the problem.
Android seems to be stretching part of the star image, creating this strange effect:
This strange effect is even visible in the graphical layout preview tool in eclipse:
The star "sprites" are: and
This is the custom style:
<style name="ratingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">#dimen/ratingBarHeight</item>
<item name="android:maxHeight">#dimen/ratingBarHeight</item>
</style>
And this is the xml code in the layout:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="#dimen/ratingBarHeight"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:numStars="5"
android:stepSize="1.0"
style="#style/ratingBar" />
The height is defined as follows:
<dimen name="ratingBarHeight">32dip</dimen>

I had the same problem. The reason was that my drawable was smaller than #dimen/ratingBarHeight, it was 22 pixels. Changing #dimen/ratingBarHeight to 22dip fixed it for me, the strange effect disappeared.

Related

Android RatingBar rating is not set correctly

I use two RatingBars in my xml layout:
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.25"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.25"
android:rating="4.5"/>
Even though I set ratings to 4.25 and 4.5, both RatingBars display wrong number of stars filled. On an Android 6 device it looks like this:
On an android 4.3 device, it looks like this:
But on xml design view, I can see 4.25 and 4.5 are set. Can anyone tell me why? I do not do anything with the rating bars in my code).
Thanks.
In my opinion the problem is related to android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint.
Try to add following lines to your rating bar:
android:progressTint="Color1"
android:progressBackgroundTint="Color2"
android:secondaryProgressTint="Color3"
also try to add style to your rating bar as following:
<style name="RatingBar" parent="Theme.AppCompat"">
<item name="colorControlNormal">#color/yourColor1</item>
<item name="colorControlActivated">#color/yourColor2</item></style>
and finally add a the following line in your rating bar
style="#style/RatingBar"
It will work for you.

How to reduce the space around rating bar in android

I have included a rating bar in android, and now I need to place a text view to immediate right if the rating bar.But I failed to do the same since, there is a lot of unwanted space (rectangular blue box) around the rating bar, which prevents me from placing the textview to its immediate right side. Is there any way to reduce this space around the rating bar , so that both the textview and the rating bar comes in same line and textview is placed next to the rating bar without a gap.Please help me with a good support! Thanks in advance! Here is my xml code for it.
<RatingBar
android:id="#+id/overall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="70dp"
android:numStars="5"
android:rating="0.0"
android:scaleX="0.4"
android:scaleY="0.4"
android:stepSize="0.01" />
You can use android default styles, Like:
style="#android:style/Widget.Holo.Light.RatingBar.Small"
in you xml layout. I am using above and have no space around it.
You can check variants here
I tried to use different suggestion but i was unsuccessful with the Android Rating bar removal of extra padding. All i did downloaded ic icons from https://material.io/icons/ and use star and star bordered icon and programmed them with switch cases.
While using the base style for the RatingBar, set the minHeight to 0dp. The base minHeight in the style itself was preventing the view from scaling down. Setting it to 0 should work as you expect a normal view (we set ours to wrap_content).
Tried to use the base (#android:style/Widget.RatingBar) and small (#android:style/Widget.DeviceDefault.RatingBar.Small and #android:style/Widget.Holo.Light.RatingBar.Small) but both fixed/limited the size of the the RatingBar regardless of what icon is used. Looking at their codes, it was no surprise.
<style name="Widget.RatingBar">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">#drawable/ratingbar_full</item>
<item name="indeterminateDrawable">#drawable/ratingbar_full</item>
<item name="minHeight">57dip</item>
<item name="maxHeight">57dip</item>
<item name="thumb">#null</item>
<item name="mirrorForRtl">true</item>
</style>
<style name="Widget.Material.RatingBar.Small" parent="Widget.RatingBar.Small">
<item name="progressDrawable">#drawable/ratingbar_small_material</item>
<item name="indeterminateDrawable">#drawable/ratingbar_small_material</item>
<item name="minHeight">16dp</item>
<item name="maxHeight">16dp</item>
</style>
<style name="Widget.Holo.Light.RatingBar.Small" parent="Widget.RatingBar.Small">
<item name="progressDrawable">#drawable/ratingbar_small_holo_light</item>
<item name="indeterminateDrawable">#drawable/ratingbar_small_holo_light</item>
<item name="minHeight">16dip</item>
<item name="maxHeight">16dip</item>
</style>
Setting the scales didn't work right either.

Smaller Custom RatingBar: Material Design

I am building an app which uses a non-clickable (indicator) ratingbar. Now, when the ratingbar IS clickable, it has two different modes. When clicked the icons turn red (red is the accentColor in my styles). When not clicked, the stars are an ugly gray with a black outline. When a rating bar is set to unclickable (indicator), the stars are permanently black-and-gray.
Additionally, I would like to make the stars smaller. Can I do both of the above things without defining custom drawables? If I must define custom drawables, how can I access the preexisting "clicked star" drawable, so that I do not need to create my own?
Thanks
<RatingBar
style="#style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="0.5" />
and add this in your styles xml file
<style name="RatingBar"
parent="android:style/Widget.Material.RatingBar.Small">
<item name="colorControlNormal">#color/primary_light</item>
<item name="colorControlActivated">#color/primary_dark</item>
</style>
visit my Blog Post and see working example. This way you dont need to customise ratingBar.

How to increase height of ProgressBar in ICS/JB

I am using the Android progressbar in one of my widgets:
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressbar_Horizontal"
android:max="100"/>
In Android 2.x it looks well, like in the following picture. I have written the % on top of the bar itself.
But if I change in the Android Manifest
android:targetSdkVersion
to "15" the progressbar looks totaly different. It is now a thin blue line instead of a bar. The problem is that I have written above the progress bar some text, in particuallary % of the progress.
Thus as the bar is so thin this looks odd.
I cannot figure out how to increase the height of the bar again to e.g. 50dp. If I try android:layout_height="50dp" it stays still same thin.
First, you need to define the style of your progress bar in values->styles.xml of your project. something like:
<style name="tallerBarStyle" parent="#android:style/Widget.SeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">#android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">#android:drawable/progress_horizontal</item>
<item name="android:minHeight">8dip</item>
<item name="android:maxHeight">20dip</item>
</style>
Edit the maxHeight to your desired height.
Then in your ProgressBar add:
style="#style/tallerBarStyle"
You need to replace
style=”?android:attr/progressBarStyleHorizontal”
to
style="#android:style/Widget.ProgressBar.Horizontal"
and layout_height will work
android:layout_height="50dp"

Android custom rating bar image size problem

Iam building a custom rating bar. With help of kozyr's article i have created it.
But i have an issue with different image scaling sizes for different screen types.
Below i provide image with screenshots of my custom rating bar in the left, and simple imageview to the right.
This is for HVGA screen.
link to screenshot
As you see, stars in rating bar and in the imageview are the same
And this screenshot from HVGA screen
another link to the screenshot
Android somehow resizes stars in my ratingbar. What is the problem?!!
Here is the code
<RatingBar android:id="#+id/rating_lunch" style="#style/starRatingBar" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:numStars="5" android:stepSize="1.0"/>
Here goes the style:
<style name="starRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/progress_star_big</item>
<item name="android:minHeight">19px</item>
<item name="android:maxHeight">19px</item>
</style>
Try using device independent pixels instead of actual pixels. e.g.:
<item name="android:maxHeight">19dp</item>
See the docs on this topic.
Problem solved. When i added
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="7" />
to the manifest file everything became allright)

Categories

Resources