4

我制作了自己的评分栏。有 4 种尺寸的花卉图像(xdpi、hdpi 等),从 24pxx24px 到 64x64px。

<?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/ic_rating_flowers_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/ic_rating_flowers_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/ic_rating_flowers" />
</layer-list>

可绘制对象中的 rating_flowers.xml

<style name="flowersRating" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/rating_flowers</item>
    <item name="android:minHeight">24dip</item>
    <item name="android:maxHeight">64dip</item>
</style>

在样式.xml

<TableRow
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dip" >

    <TextView
        android:text="@string/mood_headache" />

    <RatingBar
        android:id="@+id/moodHeadacheRating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"    
        android:numStars="3"
        android:stepSize="1.0"
        android:rating="0" 
        style="@style/flowersRating" />

 </TableRow> 

和活动

而我所看到的

我所看到的

和来自drawable-ldpi的图像

在此处输入图像描述 在此处输入图像描述

4

5 回答 5

3

尝试删除

android:padding="5dip"

来自 TableRow,因为它会在可绘制的花朵上方产生一个填充。

于 2012-12-15T07:52:57.640 回答
1

在您的评分栏更改的 XML 中

android:layout_height="wrap_content"

android:layout_height="[some number]sp".

这将解决截断图像的问题。

DisplayMetrics可用于获取有关显示器的一般信息,然后找出要使用的适当单位,但是使用android 单位转换器要简单得多。

于 2014-06-01T00:28:42.103 回答
1

使用样式作为 ?android:attr/ratingBarStyleSmall

<RatingBar
android:id="@+id/rating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:progressDrawable="@drawable/ratingbar_selector"
android:rating="2.0"
android:stepSize="1.0" />

并且自定义评分栏选择器将是: ratingbar_selector.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@android:id/background"
        android:drawable="@drawable/ic_unselected_star" />
    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/ic_unselected_star" />
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/ic_selected_star" />
</layer-list>

IMP 注意:如果自定义评级栏图标大小为 48x48、50x50 等,则将图标放入 xxhdpi 文件夹(因为我使用了较小的(36x36)评级图标,这会产生同样的问题)。然后我使用大小为 48x48 的评分栏图标。

于 2018-02-22T10:48:22.170 回答
0

我在这里遇到了完全相同的问题。对我来说,问题不在于代码,而在于图像本身。就我而言,解决方案是将照片手动调整为我想要的尺寸(IE 24x24 或 64x64)并将它们放入正确的文件夹中。

我尝试了多种方法,但似乎

<item name="android:minHeight">24dip</item>
<item name="android:maxHeight">64dip</item>

对我来说,一点代码不会做任何事情。尝试自己调整图像大小,看看是否能解决问题。

-Sil

于 2015-09-29T18:18:00.870 回答
0

android:layout_height="0dp"

https://stackoverflow.com/a/44992485/4238544

于 2017-07-09T02:36:04.267 回答