【发布时间】:2015-01-07 08:43:05
【问题描述】:
您好,我正在使用带有自定义图像的自定义评分栏。我需要在星星之间提供空间。当我增加最小高度和最大高度时,星星图像保持不变。
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="5dp">
<TextView
android:id="@+id/allreviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Rating"
android:layout_marginLeft="8dp"
android:textSize="14sp" />
<RatingBar
android:id="@+id/reviewallrating"
style="@style/customRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="@+id/allreviews"
android:isIndicator="false"
android:numStars="5"
android:stepSize="0.1" />
</RelativeLayout>
样式: @drawable/star_rating_bar_full 12浸 12浸
star_rating_bar_full.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/star_ratingbar_full_empty" />
<!-- <item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/star_ratingbar_full_empty" /> -->
<item android:id="@+android:id/progress"
android:drawable="@drawable/star_ratingbar_full_filled" />
</layer-list>
star_ratingbar_full_empty:
<?xml version="1.0" encoding="utf-8"?>
<!-- This is the rating bar drawable that is used to
show a filled cookie. -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star_gray" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star_gray" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star_gray"/>
<item android:drawable="@drawable/star_gray" />
</selector>
star_ratingbar_fullfilled.xml:
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/yellow_star" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/yellow_star" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/yellow_star" />
<item android:drawable="@drawable/yellow_star" />
我在样式中使用了 style="?android:attr/ratingBarStyle" 但输出仍然保持不变。
【问题讨论】:
-
您可以简单地在 PNG 的 左右 两侧添加一些空白区域。顺便说一句....
minimum height and maximum height与您要操作的 width 有什么关系? -
好的。我使用评级栏宽度作为 match_parent 但它与多颗星一起使用,即超过 5 颗星并且尺寸仍然太小。
-
没有。有一些沟通问题。将 RatingBar 的宽度保留为
wrap_content。在 GIMP(或您使用的任何 图形编辑器 程序)中增加灰色和黄色 PNG 的宽度。只是画布,没有拉伸星星。 -
非常感谢。解决了我的问题
-
我将我的 cmets 收集到一个答案中,以便您可以接受它并将该问题从未回答的问题队列中删除。