android ratingbar星星显示

来源:互联网 发布:五级三阶制算法 编辑:程序博客网 时间:2024/06/03 22:58


android 评论星星的显示,


格式:






一般想显示自己项目中的效果需要自定义


java文件

import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.widget.RatingBar;import android.widget.RatingBar.OnRatingBarChangeListener;public class MainActivity extends Activity {private RatingBar ratingBar = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ratingBar = (RatingBar) findViewById(R.id.ratingBar1);// 设置分数// ratingBar.setRating(2.3f);// 设置步长// ratingBar.setStepSize(0.1f);// 设置监听ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {@Overridepublic void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {ratingBar.setRating(rating);Log.i("RatingBar", "当前评分: " + rating + "fromUser: " + fromUser);}});}}

布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <RatingBar        android:id="@+id/rb_ratingBar"        style="@style/myRatingBar"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/tv_comment"        android:layout_centerHorizontal="true"        android:layout_marginTop="10dp"        android:numStars="5"        android:stepSize="1"        android:rating="0.0"        /></LinearLayout>




参考链接 http://my.oschina.net/zhoulc/blog/127065

http://blog.csdn.net/sjf0115/article/details/7249777

0 0
原创粉丝点击