Search code examples
androidandroid-viewandroid-custom-view

ratingbar with custom images


Is it possible to create a custom rating bar like this? If yes, can you give me an example on how to do it?

enter image description here

Thanks in advance!


Solution

  • EDIT: This is not an appropriate answer, as OP wanted to customize RatingBar. But it is still a solution.

    It is possible. You just have to put each one of the five image resources in your project and then, make a layout like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="60dp"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:gravity="left"
    android:orientation="vertical"
    android:weightSum="5" >
    
    <ImageView
        android:id="@+id/oneStar"
        android:layout_width="50dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />
    
    <ImageView
        android:id="@+id/twoStars"
        android:layout_width="50dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
        android:visibility="visible" />
    
    <ImageView
        android:id="@+id/threeStars"
        android:layout_width="50dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
        android:visibility="visible" />
    
    <ImageView
        android:id="@+id/fourStars"
        android:layout_width="50dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
        android:visibility="visible" />
    
    <ImageView
        android:id="@+id/fiveStars"
        android:layout_width="50dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
        android:visibility="visible" />
    

    Put your resources as source of your ImageViews. That should be a start for you :D