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

    四、效果图

  • 相关阅读:
    MS SQL Server 定时任务实现自动备份
    Python日期的加减等操作
    C# DbHelperSQL 类,从东软生成器提取而来
    C# List<string>和ArrayList用指定的分隔符分隔成字符串
    自定义可视化调试工具(Microsoft.VisualStudio.DebuggerVisualizers)
    查看SQLServer最耗资源时间的SQL语句
    程序员不适合创业
    如何写高质量,不繁琐的会议记录?
    C#中的Attribute详解(下)
    微信小程序教程系列
  • 原文地址:https://www.cnblogs.com/kingshow123/p/ratingbar.html
Copyright © 2011-2022 走看看