Android RatingBar星星评分控件实例代码
更新时间:2017年06月07日 09:45:34 作者:DistanceZK
本文通过实例代码给大家介绍了Android RatingBar星星评分控件,非常不错,具有参考借鉴价值,需要的朋友参考下吧
效果图:

直接上代码:
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.example.blogtest.MainActivity">
<!--numStars设置星星的数量,stepSize默认的评分-->
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb_main_rating"
android:numStars="5"
android:stepSize="0.5"
/>
</LinearLayout>
Java代码:
package com.example.blogtest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.RatingBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private RatingBar rb_main_rating;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获得RatingBar的控件
rb_main_rating = (RatingBar) findViewById(R.id.rb_main_rating);
//给控件设置监听事件
rb_main_rating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast t=Toast.makeText(MainActivity.this,"您的评分为:"+rating,Toast.LENGTH_SHORT);
t.setGravity(Gravity.CENTER,0,0);
t.show();
}
});
}
}
以上所述是小编给大家介绍的Android RatingBar 评分控件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
android之视频播放系统VideoView和自定义VideoView控件的应用
这篇文章主要介绍了android之视频播放系统VideoView和自定义VideoView控件的应用,需要的朋友可以参考下2017-03-03
Android AsyncTask 后监听异步加载完毕的动作详解
这篇文章主要介绍了Android 使用AsyncTask 后监听异步加载完毕的动作的相关资料,需要的朋友可以参考下2016-11-11
android 仿微信demo——微信消息界面实现(移动端)
本系列文章主要介绍了微信小程序-阅读小程序实例(demo),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能给你们提供帮助2021-06-06
android WindowManager的简单使用实例详解
这篇文章主要介绍了android WindowManager的简单使用,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-08-08
Android StatusBar 透明化方法(不同的版本适配)
本篇文章主要介绍了Android StatusBar 透明化方法(不同的版本适配),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-01-01


最新评论