这里分享一个食之无味,弃之可惜的鸡肋。项目中的订单要写待评价订单,ios那边犯难了,没有对应的控件。android这边第一反应就觉得简单,因为ratingbar。结果发现确实有它坑的地方。提出ratingbar被放弃的两个原因。
一、替换星星无法指定星星的高度(**)
二、无法指定星星之间的间距
所以网上出了很多自定义的ratingbar控件。。。。只能投机取巧。稍微润色下,ratingbar就可以使用了。
三、解决方案
1、xml文件中的引用
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="64px"
android:layout_marginTop="45px"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5px"
android:text="效率:"
android:textColor="@color/textcolor"
android:textSize="28px" />
<RatingBar
android:id="@+id/rtb_count"
style="@style/RatingbarBigStyle"
android:layout_width="wrap_content"
android:layout_height="62px"
android:layout_marginLeft="5px"
android:numStars="5"
android:rating="4"
android:stepSize="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22px"
android:layout_marginTop="5px"
android:text="好"
android:textColor="@color/textcolorgray"
android:textSize="24px" />
</LinearLayout>
2、关键看 style=”@style/RatingbarBigStyle”
<!--自定义Ratingbar样式,38px-->
<style name="RatingbarBigStyle" parent="@android:style/Widget.RatingBar">
<!--定义星星图片-->
<item name="android:progressDrawable">@drawable/bigratingbar_drawable</item>
<!-- 根据自定义星星图片的大小,设置相应的值,否则可能显示不全 -->
<item name="android:numColumns">5</item>
<item name="android:minHeight">62px</item>
<item name="android:maxHeight">62px</item>
</style>
这里注意的是,不能看预览的图片,要经过真机的千锤百炼,只要就是设定在xhdpi(美工标注图片)中,因为此时图片比例:标注为1:1。设定一张与之大小相同的图片。如。同为62px。。。然后根据android运行机制,会对获取到的图片进行自动缩放。。。星星就跟着缩放了。当然有条件的话,自然是3套最好。。。。
2、@drawable/bigratingbar_drawable
<?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/icon_touchnonestar" />
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/icon_touchnonestar" />
<item
android:id="@android:id/progress"
android:drawable="@drawable/icon_touchstared" />
</layer-list>
3、星星之间的间距怎么办。
去求美工给你切个间距不就可以了吗。当然不肯的话,只能像我这样,用扣扣截图工具了。。。心酸
四、目前还未发现什么不妥之处。等待继续填坑。未完待续。。。