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

项目中给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的父布局是什么就用什么布局

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值