tôi đã thực hiện một thanh giá tùy chỉnh từ this stackoverflow thread mà không hiển thị nhiều hơn một ngôi sao ngay cả khi tôi đặt numStars-5 hoặc bất kỳ số khácTuỳ chỉnh RatingBar không hiển thị hơn 1 sao
Đây là Bộ luật .
Tôi đang sử dụng bản vẽ vector cho hình ảnh.
RatingBar trong main_activity.xml
<RatingBar
android:id="@+id/ratingBarValue"
style="@style/Fuel_Indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:numStars="5"
android:stepSize="1.0"
android:max="5" />
Fuel_Indicator phong cách trong phong cách.
<style name="Fuel_Indicator" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/fuel_bar_full</item>
<item name="android:indeterminateDrawable">@drawable/fuel_bar_full</item>
<item name="android:minHeight">23dip</item>
<item name="android:maxHeight">25dip</item>
</style>
Các fuel_bar_filled.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/fuel_bar_empty" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/fuel_bar_empty" />
<item android:id="@android:id/progress"
android:drawable="@drawable/fuel_bar_filled" />
fuel_bar_empty.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">`
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:drawable="@drawable/ic_fuel_empty" />
</selector>
fuel_bar_filled.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">`
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_full" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_full" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_full" />
<item android:drawable="@drawable/ic_fuel_full" />
</selector>
lý do bạn cho rằng mình sử dụng 'SVG'? –
@VladMatvienko vì OP đã viết trong câu hỏi. và xin lỗi nó là 'Vector Drawable'. – Ironman
Cảm ơn bạn. Nó làm việc. Tôi tự hỏi vấn đề là gì với Vector Drawable. –