如何给评分栏星星之间的间距 android?
How to give spacing between rating bar stars android?
您好,我正在使用带有自定义图像的自定义评分栏。我需要在星星之间提供 space。当我增加最小高度和最大高度时,星形图像保持不变。
<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
12dip
12dip
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" 但输出仍然保持不变。
如果你为星星使用Drawable。根据您在 png 图像中的要求,确保您的可绘制对象有一些左填充。
否则通过代码无法正常工作。几天前我遇到了同样的问题。我通过使用左填充图像完成了。希望有用。
您可以简单地在 PNG 的左侧和右侧添加一些空的 space。
也就是说,在 GIMP(或您使用的任何图形编辑器程序)中增加灰色和黄色 PNG 的宽度。
只是 canvas,没有拉伸星形图标。
您好,我正在使用带有自定义图像的自定义评分栏。我需要在星星之间提供 space。当我增加最小高度和最大高度时,星形图像保持不变。
<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 12dip 12dip
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" 但输出仍然保持不变。
如果你为星星使用Drawable。根据您在 png 图像中的要求,确保您的可绘制对象有一些左填充。
否则通过代码无法正常工作。几天前我遇到了同样的问题。我通过使用左填充图像完成了。希望有用。
您可以简单地在 PNG 的左侧和右侧添加一些空的 space。
也就是说,在 GIMP(或您使用的任何图形编辑器程序)中增加灰色和黄色 PNG 的宽度。
只是 canvas,没有拉伸星形图标。