10

Does anyone knows if its possible to make the RatingBar go from right-to-Left instead of left to right, or have an idea how to do it?

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130

3 Answers3

6

You can use android:rotation="180" in your Ratingbar to rotate it i used this way on my read-only Ratingbars, i dont know if this will effect interacting with the Ratingbar.

ibmkhd
  • 799
  • 2
  • 14
  • 25
  • 1
    then you also should rotate drawables in graphics editor which is not easier then just to set reverse amount of stars – ar-g May 13 '16 at 09:41
5

Use attribute android:scaleX="-1"

OR

package com.example.selection;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.RatingBar;

public class InvertRatingBar extends RatingBar {

    public InvertRatingBar(Context context) {
        super(context);
    }

    public InvertRatingBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public InvertRatingBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int width = this.getMeasuredWidth();
        event.setLocation(width - event.getX(), event.getY());
        return super.onTouchEvent(event);
    }

    @Override
    protected synchronized void onDraw(Canvas canvas) {
        int width = this.getMeasuredWidth();
        Matrix matrix = canvas.getMatrix();
        matrix.preTranslate(width, 0);  
        matrix.preScale(-1.f, 1);
        canvas.setMatrix(matrix);
        super.onDraw(canvas);
    }
}
Mika
  • 51
  • 1
  • 2
0

You have to customize the RatingBar..

However you just have to play tricks with displaying RatingBar Images & then some sort of reverse calculations.

Trick will be displaying reverse Images in RatingBar.. swap selected and unselected images in RatingBar.

Allow user to rate on RatingBar. You have to swap selected and unselected calculations. I mean you have to do reverse calculations.

Complete Working example of custom RatingBar on StackOverflow answered by me only.

Download RatingBar icons from here : http://developer.android.com/guide/practices/ui_guidelines/icon_design.html

Community
  • 1
  • 1
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104