FlexibleRatingBar is an enhanced version of Android's default RatingBar.
The default Android RatingBar scales very poorly, and requires custom drawables to do pretty much anything besides the default. FlexibleRatingBar creates polygons with however many vertices you want, and scales them to fit the the allotted space, so it scales properly and predictably. It also gives you a lot of flexibility with regards to color.
FlexibleRatingBar is compatible all the way back to API 4. To get started, add the following dependency to your build.gradle
.
(currently getting this set up with maven/jcenter. will update when available)
<amagi82.flexibleratingbar.FlexibleRatingBar
android:id="@+id/flexibleRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="6"
android:rating="1.5"
android:stepSize="0.5"
app:colorFillOff="@android:color/transparent"
app:colorFillOn="@color/tealA400"
app:colorFillPressedOff="@android:color/transparent"
app:colorFillPressedOn="@color/tealA200"
app:colorOutlineOff="@color/teal800"
app:colorOutlineOn="@color/teal900"
app:colorOutlinePressed="@color/teal500"
app:polygonVertices="7"
app:polygonRotation="0"
app:strokeWidth="5dp"/>
Add <amagi82.flexibleratingbar.FlexibleRatingBar/>
to your layout, and use the same as you would any other widget.
layout_width
and layout_height
will scale the rating bar appropriately.
In addition, you can alter any of the above settings in xml, or do it in code.
The colors should be self-explanitory. polygonVertices
is the number of points on your star.
You can go down to 2, which creates a diamond, or enter 0 and get circles.
By default, polygons are drawn with one point centered at the top. polygonRotation
rotates it by int degrees.
strokeWidth
is the thickness of the outline around the star.
In code, you can change any of the above with myRatingBar.setColorFillOff(Color.argb(55,145,122,235))
and so on.
In addition, you can call setInteriorAngleModifier
, which adjusts the interior angle of the polygons.
Default is 2.2, and I recommend keeping it between 1(round) and 3(very pointy).
Jim Pekarek - [email protected]
Copyright (C) 2015 James Pekarek
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.