2016-02-05 69 views
1

的大小我想为我的Android应用程序制作自定义RatingBar,其中我可以更改RatingBar的默认大小和颜色。为此我写了样式CustomRatingBar这样的:无法更改自定义RatingBar

<style name="CustomRatingBar" parent="@android:style/Widget.RatingBar"> 
    <item name="android:progressDrawable">@drawable/custom_ratingbar</item> 
    <item name="android:minHeight">25dp</item> 
    <item name="android:maxHeight">25dp</item> 
</style> 

但大小没有改变的,而它缩小评级酒吧这样的: enter image description here

绘制对象文件是:custom_ratingbar.xmlcustom_ratingbar_emptycustom_ratingbar_filled

在我的XML,的RatingBar看起来象下面这样:

  <RatingBar 
        android:id="@+id/RatingBar" 
        style="@style/CustomRatingBar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:isIndicator="true" 
        android:numStars="5" /> 

如何更改评级栏的星形大小而不缩小?

+0

使用:'style =“?android:attr/ratingBarStyleSmall”' –

+0

你使用的是什么图标大小?使用更大的图标,如48x48或50x50并保存在xxhdpi文件夹中。 – Mubarak

回答

2

试试这个,

自定义评分栏风格使用android的ratingBar小风格。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="CustomRatingBar" parent="@android:style/Widget.RatingBar" > 
<item name="android:numStars">5</item> 
<item name="android:rating">4.5</item> 
<item name="android:stepSize">0.5</item> 
<item name="android:layout_width">wrap_content</item> 
<item name="android:layout_height">wrap_content</item> 
<item name="android:paddingBottom">44dip</item> 
<item name="android:layout_marginLeft">4dip</item> 
<item name="android:layout_marginTop">4dip</item> 

检查example.的一样。

其他解决方案是:

Android不会缩放评级栏图标。当你降低minHeight和maxHeight android会永远裁剪图片上显示的图标。似乎唯一的解决方案是为具有所需尺寸的星星提供自己的图标,并将minHeight和maxHeight设置为图标的大小。

+0

它在底部留出一些空间,但星星的大小没有变化。 –

+0

你有没有尝试像例子链接?@pialkanti –

+0

我已经遵循了自定义ratingBar的示例教程。 –