Is it possible to change the direction of RatingBar?

Does anyone know if it is possible to make a RatingBar from right to left, and not from left to right, or is there an idea how to do this?

+8
android android-layout
source share
3 answers

You must configure RatingBar ..

However, you just need to play tricks with the RatingBar image display, and then some kind of inverse calculation.

Trick will display the inverse images in the RatingBar .. will replace the selected and unselected images in the RatingBar.

Allow user to rate RatingBar . You must swap selected and unselected calculations. I mean, you have to do the inverse calculations.

A full working example of a custom RatingBar on https://stackoverflow.com/a/5607/ ... was answered only by me.

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

0
source share

You can use android:rotation="180" in your rating to rotate it. I used this method in my read-only ratings, I donโ€™t know if this will affect the interaction with the rating.

+4
source share

Use android:scaleX="-1" 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); } } 
+3
source share

All Articles