RatingBar custom picture



The above are two pictures (size h*w = 50*94) that need to be used. There is a certain transparent area left and right of the picture as the space between the stars, which should not be seen in the blog,
1. Put them in different folders to adapt to different resolutions of the screen,
If you try to put only one directory (drawable nodpi), some mobile phones may display problems

2. Create a new file named five rating bar.xml and set the replacement 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/morensanjiaoxing"/>

    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/morensanjiaoxing"/>

    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/anxiasanjiaoxing"/>
</layer-list>

3. Add fixratingbar in style file, limit minHeight and maxHeight, and use px as unit
Advantages: prevent stretch or incomplete display under different resolutions, but it will affect the display effect,
Disadvantages: obviously, stars will be smaller in large resolution

<resources>
    <style name="FiveRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/five_rating_bar</item>
        <item name="android:minHeight">50px</item>
        <item name="android:maxHeight">50px</item>
        <item name="android:minWidth">94px</item>
        <item name="android:maxWidth">94px</item>
    </style>
</resources>

4. Define the control, reference style = "@ style/FiveRatingBar", control properties will not be discussed here

<RatingBar
    android:id="@+id/evaluation_RatingBar"
    style="@style/FiveRatingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:isIndicator="false"
    android:numStars="5"
    android:rating="1.0"
    android:stepSize="1.0"
    />

Keywords: Android xml Mobile encoding

Added by djlfreak on Sun, 05 Apr 2020 03:00:02 +0300