zoukankan      html  css  js  c++  java
  • RatingBar评分控件的使用

        RatingBar主要用在电子相册,网上书店和对文章进行评分的功能。

    一、建立工程,如图

    二、activity_main.xml中代码

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="评分控件的使用"
            />
        <RatingBar 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar"
            />
        
    </LinearLayout>
    View Code

    三、MainActivity.java中代码

    package com.study.ratingbar;
    
    import android.os.Bundle;
    import android.R.integer;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.RatingBar;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    import android.widget.Toast;
    
    public class MainActivity extends Activity implements OnRatingBarChangeListener{
    
        private RatingBar ratingBar;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            ratingBar = (RatingBar)this.findViewById(R.id.ratingBar);
            ratingBar.setMax(100); //设置最大刻度
            ratingBar.setProgress(20); //设置当前的刻度
            ratingBar.setOnRatingBarChangeListener(this);
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {
            int progress = ratingBar.getProgress();
            Toast.makeText(MainActivity.this, "progress:" + progress +" rating:"  + rating, 1).show();
            
        }
        
    }
    View Code

    四、效果图

  • 相关阅读:
    kafka 的基本概念及使用场景
    使用RedisTemplate执行Redis脚本
    SpringBoot使用Lua脚本操作Redis
    Java不定参数Object… obj 和 Object[] 的区别
    IntelliJ IDEA添加快捷键自动输入@author信息
    使用Guava RateLimiter限流以及源码解析
    go fileserver
    记录了prometheus 告警指标
    https://mp.weixin.qq.com/s/ZBsZHQtAz_vKS8fwvHKB3g图文分析Kubernetes认证、授权和准入控制
    es不停机滚动update
  • 原文地址:https://www.cnblogs.com/kingshow123/p/ratingbar.html
Copyright © 2011-2022 走看看