Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the RatingBar direction?

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?

like image 994
Asaf Pinhassi Avatar asked Sep 29 '11 06:09

Asaf Pinhassi


People also ask

How do I change the rating bar on my Android?

You can create custom material rating bar by defining drawable xml using material icon of your choice and then applying custom drawable to rating bar using progressDrawable attribute. Below drawable xml uses thumbs up icon for rating bar.

How do I turn off RatingBar touch on Android?

After applying either style="? android:attr/ratingBarStyleSmall" or scaleX/scaleY the click interaction with RatingBar is disabled. This works for me. Hope this helps you!

How do you set color rating bars?

First, change progress color of rating bar. Its done by two ways, either by applying theme on RatingBar or by manually using LayerDrawable. That's it. android:stepSize="0.5" />LayerDrawable stars = (LayerDrawable) rating.

What is Rating bar in android user interface?

A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar.


1 Answers

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);
    }
}
like image 71
Mika Avatar answered Oct 31 '22 23:10

Mika