无法更改自定义RatingBar的大小 [英] Can't change the size of custom RatingBar

查看:274
本文介绍了无法更改自定义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.xml 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>

检查示例.

其他解决方案是:

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的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆