Android 滑动时获取RatingBar值
我想在滑动以更改文本评级值(差、好等)时读取评级条的值,我使用Android 滑动时获取RatingBar值,android,ratingbar,Android,Ratingbar,我想在滑动以更改文本评级值(差、好等)时读取评级条的值,我使用setOnRatingBarChangeListener进行此操作,但在用户将手指从评级条上松开后,此功能会起作用。我也试过了,但没有成功。 当然,我有xml格式的android:isIndicator=“false”,但没有任何更改 有没有其他的监听器,即时获得评级的代码-因为星星在滑动时被正确地重新绘制。 提前谢谢 Roman您必须扩展分级栏,覆盖onTouchEvent(),并检查MotionEvent.ACTION\u MOV
setOnRatingBarChangeListener
进行此操作,但在用户将手指从评级条上松开后,此功能会起作用。我也试过了,但没有成功。
当然,我有xml格式的android:isIndicator=“false”
,但没有任何更改
有没有其他的监听器,即时获得评级的代码-因为星星在滑动时被正确地重新绘制。
提前谢谢
Roman您必须扩展
分级栏
,覆盖onTouchEvent()
,并检查MotionEvent.ACTION\u MOVE
事件
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
if (isPressed()) {
final float x = event.getX();
final float THRESHOLD = 1.0;
if (Math.abs(x - prevX) > THRESHOLD) {
getProgress(); // Now compare with previous progress
}
prevX = x;
}
}
}
该代码在滑动时在Log cat上打印额定值的当前值
final RatingBar ratingBar = (RatingBar) findViewById(R.id.rating_bar);
ratingBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
Log.d("LOG", String.format("%f", ratingBar.getRating());
}
return false;
}
});
你能详细解释一下如何使用这个吗