Ich leide unter Step-Größe Problem mit Android-Standard-RatingBar.Standard-RatingBar Set Icon-Problem nach Schrittgröße (Get RatingBar Wert ist in Ordnung)
-Code
private RatingBar rb;
private TextView tvSetRatingBar;
private Button btnGetRatingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rb = findViewById(R.id.rb);
tvSetRatingBar = findViewById(R.id.tvSetRatingBar);
btnGetRatingBar = findViewById(R.id.btnGetRatingBar);
btnGetRatingBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String strGetData = String.valueOf(rb.getRating());
tvSetRatingBar.setText("Get Rating = " + strGetData);
}
});
}
Layout-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<RatingBar
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:isIndicator="false"
android:numStars="6"
android:stepSize=".1" />
<TextView
android:id="@+id/tvSetRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:hint="Set RatingBar"
android:padding="10dp" />
<Button
android:id="@+id/btnGetRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:hint="Get RatingBar"
android:padding="10dp" />
</LinearLayout>
Problem
Sie können sehen, in obigem Bild getRating Wert ist in TextView eingestellt ist in Ordnung, aber RatingBar Symbol ist nicht richtig eingestellt, es ist immer 2.5 gesetzt. Ich habe Standard-RatingBar verwenden.
android: stepSize = ". 1" im Layout festgelegt.
Entschuldigung, versehentlich geklickt. Danke für die Antwort. –
Sorry, aber wenn ich Ihren obigen Code mit AppCompatRatingBar verwenden, wird ein Fehler wie Fehler angezeigt: error: Attribut 'com.example.android.ratingbarandcalanderviewdemo: secondaryProgressTint' nicht gefunden. –
@DileepPatel Überprüfen Sie meine aktualisierte Antwort. Und auch im Java-Code Ihrer Aktivität sollte "AppCompatActivity" und nicht nur "Activity" erweitert werden. –