zoukankan      html  css  js  c++  java
  • 安卓学习第23课——ratingBar

    progressBar这部分相对而言比较简单

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
      <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:src="@drawable/lijiang" />
        <RatingBar
            android:id="@+id/ratingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:numStars="5"
            android:progress="255"
            android:stepSize="0.5" />
    </LinearLayout>
    package com.example.ratingbar;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ImageView;
    import android.widget.RatingBar;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    
    public class MainActivity extends Activity {
    
        ImageView image;
        RatingBar ratingBar;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            image=(ImageView) findViewById(R.id.image);
            ratingBar=(RatingBar) findViewById(R.id.ratingBar);
            ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){
    
                @Override
                public void onRatingChanged(RatingBar ratingBar, float rating,
                        boolean fromUser) {
                    image.setImageAlpha((int) (rating*255/5));
                    
                }
                
            });
        }
    }
  • 相关阅读:
    C#: Create a WebRequest with HTTP Basic Authentication
    C# 集合
    BAT CMD 批处理文件脚本 -2
    年龄排序
    士兵买香蕉
    ACM交换生问题
    ACM卡片游戏
    ACM费马大定理
    ACM定外卖问题
    ACM汽车行程问题求最少的支付钱数
  • 原文地址:https://www.cnblogs.com/Yvettey-me/p/3935573.html
Copyright © 2011-2022 走看看