有人知道是否可以让RatingBar从右到左而不是从左到右,或者有什么想法吗?
android:rotation="180"
进行旋转。我在只读评分条上使用了这种方法,但我不知道是否会影响与评分条的交互。使用属性android:scaleX="-1"
或者
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);
}
}
你必须自定义 RatingBar
。
然而,你只需要玩一些技巧来显示 RatingBar
图像,然后进行某种形式的反向计算。
技巧是在 RatingBar 中显示反向图像。在 RatingBar 中交换选择和未选择的图像。
允许用户对 RatingBar
进行评分。你必须交换选择和未选择的计算方式。也就是说,你必须进行反向计算。
我自己回答了 StackOverflow 上的自定义 RatingBar
完整工作示例。
从这里下载 RatingBar
图标:http://developer.android.com/guide/practices/ui_guidelines/icon_design.html