ratingBar star rating bar

 

 

<?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>
Main interface
Image = the findViewById Val <the ImageView> (R.id.image) 
        Val RatingBar = the findViewById <RatingBar> (R.id.rating) 
        ratingBar.onRatingBarChangeListener = {RatingBar.OnRatingBarChangeListener RatingBar, Rating, FROMUSER ->
             // When Star Rating bar trigger a change in the method of scoring
             // dynamically change the picture of transparency, where 255 is the maximum star rating bar
             // five stars represents the maximum value of 255 
            image.imageAlpha = (Rating * 255/5 ) .toInt ( ) 
            Print (Rating) 
        }
The main program

 

Guess you like

Origin www.cnblogs.com/superxuezhazha/p/11519276.html