本文介绍了无法更改自定义 RatingBar 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的 android 应用程序制作自定义 RatingBar,我可以在其中更改 RatingBar 的默认大小和颜色.为此,我为 CustomRatingBar 编写了如下样式:

I am trying to make custom RatingBar for my android app in which i can change the default size and color of RatingBar. For this purpose i have written styles for CustomRatingBar like this:

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

但是大小没有改变,而是像这样缩小了评级栏:

But the size is not changed rather it shrinks the rating bar like this:

可绘制文件是:custom_ratingbar.xmlcustom_ratingbar_empty, custom_ratingbar_filled

在我的 xml 中,RatingBar 如下所示:

In my xml, RatingBar looks like below:

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

如何在不缩小评分栏的情况下更改评分栏的星号大小?

How can i change the star size of the rating bar without shrinking it?

推荐答案

试试这个,

使用android的 ratingBar 小样式自定义评分栏样式.

custom rating bar style using android’s ratingBar small style.

<?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 设置为图标的大小.

Android won't scale a rating bar icons. When you decrease the minHeight and maxHeight android will always crop the icons as shown on the picture. There seems to be the only one solution is to provide your own icons for stars with the desired dimensions and set the minHeight and maxHeight to the size of the icons.

这篇关于无法更改自定义 RatingBar 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:16