2016-01-21 58 views
0

我想创建一个RatingBar,它不使用图像来创建边框。但我似乎无法做到。如何在不使用图片的情况下应用RatingBar边框?

这里就是我想要它看起来像:

with border

这就是我得到了(装满 - 一半是空 - 空):

filled - half empty - empty

这里是我的布局:

<RatingBar 
    android:id="@+id/ratingbar_rate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:numStars="5" 
    android:rating="2.5" 
    android:stepSize="0.5" 
    android:scaleX="3.5" 
    android:scaleY="3.5" 
    style="?android:attr/ratingBarStyleIndicator" 
    android:isIndicator="false" 
    android:progressTint="@color/star" 
    android:progressBackgroundTint="@color/star_border" 
    android:secondaryProgressTint="@color/star_partially_empty" 
    android:backgroundTint="@color/star_partially_empty" 
/> 
+0

问题解决了吗? – piotrek1543

回答

0

好了,所以我使用了自定义绘制layer-list和Android将是一个做休息。

RatingBar

<RatingBar 
    android:id="@+id/ratingbar_rate" 
    style="@style/rateUsBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:numStars="5" 
    android:rating="0" 
    android:stepSize="1" 
    android:layout_gravity="center" 
/> 

styles.xml

<resources> 
    ... 
    ... 
    <style name="rateUsBar" parent="@android:style/Widget.RatingBar"> 
     <item name="android:progressDrawable">@drawable/rating_stars</item> 
     <item name="android:minHeight">@dimen/rate_us_star_minheight</item> 
     <item name="android:maxHeight">@dimen/rate_us_star_maxheight</item> 
    </style> 
</resources> 

rating_stars.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@android:id/background" 
     android:drawable="@drawable/rate_empty" /> //gray star for empty 
    <item 
     android:id="@android:id/secondaryProgress" 
     android:drawable="@drawable/rate_empty" /> //gray star for empty 
    <item 
     android:id="@android:id/progress" 
     android:drawable="@drawable/rate_filled" /> //yellow star for filled 
</layer-list> 

dimens.xml

<resources> 
    ... 
    ... 
    <dimen name="rate_us_star_minheight"> <!--height of your image--> </dimen> 
    <dimen name="rate_us_star_maxheight"> <!--height of your image--> </dimen> 
</resources> 

就是这样!

相关问题