首页 > 其他 > 详细

ratingBar 星级评分条

时间:2019-09-14 16:50:15      阅读:101      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

技术分享图片
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:src="@drawable/lijiang"/>
    <!-- 定义一个星级评分条 -->
    <RatingBar
        android:id="@+id/rating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:max="255"
        android:progress="255"
        android:stepSize="0.5"/>
</LinearLayout>
主界面
技术分享图片
 val image = findViewById<ImageView>(R.id.image)
        val ratingBar = findViewById<RatingBar>(R.id.rating)
        ratingBar.onRatingBarChangeListener = RatingBar.OnRatingBarChangeListener { ratingBar, rating, fromUser ->
            // 当星级评分条的评分发生改变时触发该方法
            // 动态改变图片的透明度,其中255是星级评分条的最大值
            // 5个星星就代表最大值255
            image.imageAlpha = (rating * 255 / 5).toInt()
            print(rating)
        }
主程序

 

ratingBar 星级评分条

原文:https://www.cnblogs.com/superxuezhazha/p/11519276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!