如何解决单击时如何禁用其他星星上的闪烁颜色/动画?
当我点击一颗星星时,其他星星在它变成蓝色之前闪烁,我想在点击相应星星时禁用跳舞效果/动画/背景颜色或任何其他星星。如果有人帮我找到节省时间的方法,我将不胜感激。
[<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="8dp"
android:numStars="5"
android:stepSize="1"
app:layout_constraintBottom_toTopOf="@+id/btnSubmit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/HiddenText"
app:layout_constraintVertical_bias="0.488" />][1]
rating_bar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v,MotionEvent event) {
/*
Log.i(TAG,"onTouch:1111111 " +rating_bar.getRating());
*/
if (event.getAction() == MotionEvent.ACTION_UP) {
// TODO perform your action here
String StarPosition = String.valueOf(rating_bar.getRating());
if (StarPosition.equalsIgnoreCase("1.0")) {
HiddenText.setText("Poor");
HiddenText.setTextColor(Color.parseColor("#2F8E33"));
} else if (StarPosition.equalsIgnoreCase("2.0")) {
HiddenText.setText("Bad");
HiddenText.setTextColor(Color.parseColor("#2F8E33"));
} else if (StarPosition.equalsIgnoreCase("3.0")) {
HiddenText.setText("Average");
HiddenText.setTextColor(Color.parseColor("#2F8E33"));
} else if (StarPosition.equalsIgnoreCase("4.0")) {
HiddenText.setText("Good");
HiddenText.setTextColor(Color.parseColor("#2F8E33"));
} else if (StarPosition.equalsIgnoreCase("5.0")) {
HiddenText.setText("Excellent");
HiddenText.setTextColor(Color.parseColor("#2F8E33"));
} else {
HiddenText.setText("");
}
Log.i(TAG,"onTouch:2222222222 " + rating_bar.getRating());
}
return false;
}
});
解决方法
不要使用OnTouchListener
,而是使用OnRatingBarChangeListener
rating_bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar,float rating,boolean fromUser) {
//your code in here
if(rating < 0.5f) {} // no rating or 0 stars,not filled?
else if(rating < 1.5f) {} // one star (rounded)
else if(rating < 2.5f) {} // two starts (rounded)
else...
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。