RatingBar流泪、有脚、显示不全问题

来源:互联网 发布:java表格代码怎么写 编辑:程序博客网 时间:2024/04/30 08:58

项目中给ratingbar设置了style后星星”流泪“、”有脚“


ratingstars

<?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="@mipmap/star_empty" />    <item android:id="@android:id/secondaryProgress"        android:drawable="@mipmap/star_empty" />    <item android:id="@android:id/progress"        android:drawable="@mipmap/star" /></layer-list>

style

<style name="RatingBar" parent="@android:style/Widget.RatingBar">        <item name="android:progressDrawable">@drawable/ratingstars</item>        <item name="android:minHeight">22dp</item>        <item name="android:maxHeight">22dp</item>    </style>

xml

 <RatingBar            android:id="@+id/ratingbar"            android:layout_width="wrap_content"            android:layout_height="22dp"            android:numStars="5"            android:stepSize="1"            style="@style/RatingBar"            />


代码:直接获取对应图片的高度,然后设置图片的高度。

如果是在Adapter中就写在adapter里面,如果在Activity中就写在Activity中

try {            Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.mipmap.star);            int scroeHeight = bmp.getHeight();        } catch (Exception e) {            e.printStackTrace();        }//        在需要的地方设置LayoutParams  记得图片只需要初始化一次就可以了        if(scroeHeight!=0){            LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) ratingBar.getLayoutParams();            llp.width = -2;// 包裹内容            llp.height = scroeHeight;            ratingBar.setLayoutParams(llp);        }


LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) ratingBar.getLayoutParams();
这句是ratingbar的父布局是什么就用什么布局

然后现在星星不流泪了,显示完全,但是最后一个星星最右边的角感觉少了一点 点,不过影响不大

0 0
原创粉丝点击