2016-12-20 16 views
7

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> 

Trả lời

13

Thực hiện của bạn là hoàn hảo Nhưng bạn đang sử dụng Vector Drawable gây ra sự cố này. Vì vậy, để làm việc với nó, hãy thử thay thế Vector Drawable bằng hình ảnh png trong thư mục drawable và xem ma thuật hoạt động.

bạn đang sử dụng Vector Drawable với layer-list để hình ảnh Vector Drawable của bạn vừa với toàn bộ bố cục, hãy thử thay thế bằng png để khắc phục sự cố của bạn.

+0

lý do bạn cho rằng mình sử dụng 'SVG'? –

+0

@VladMatvienko vì OP đã viết trong câu hỏi. và xin lỗi nó là 'Vector Drawable'. – Ironman

+0

Cảm ơn bạn. Nó làm việc. Tôi tự hỏi vấn đề là gì với Vector Drawable. –

Các vấn đề liên quan