2016-12-20 11 views
7

I wdrożyliśmy niestandardowy pasek znamionową z this stackoverflow thread który nie wykazuje więcej niż jedną gwiazdkę nawet jeśli ustawić numStars do 5 lub dowolny inny numerklienta RatingBar nie pokazuje więcej niż 1 gwiazda

Oto kod .

Używam rysunków wektorowych do zdjęć.

RatingBar w 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 styl w stylach.

<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> 

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> 

Odpowiedz

13

Twoja implementacja jest idealne, ale używasz Vector Drawable który jest przyczyną tego problemu. Aby z nim pracować, spróbuj zastąpić obraz Vector Drawable obrazkiem png w folderze do rysowania i zobacz, jak działa magia.

używasz Vector Drawable z layer-list więc Vector Drawable obraz nadaje się cały układ spróbować zastąpić go png który rozwiąże Twój problem.

+0

dlaczego uważasz, że używa 'SVG'? –

+0

@VladMatvienko, ponieważ OP napisał w pytaniu. i przepraszam, że to "wektor do ciągnięcia". – Ironman

+0

Dziękuję. To zadziałało. Zastanawiam się, jaki jest problem z Vector Drawable. –

Powiązane problemy