• android_ratingBar


    主文件

    package cn.com.sxp;

    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.RatingBar;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    import android.widget.TextView;

    public class RatingBarActivity extends Activity implements OnRatingBarChangeListener{
    private RatingBar smallRatingBar = null;
    private RatingBar indicatorRatingBar = null;
    private TextView ratingText = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ratingText = (TextView) findViewById(R.id.textView);
    indicatorRatingBar = (RatingBar) findViewById(R.id.rbFour);
    smallRatingBar = (RatingBar) findViewById(R.id.rbThree);

    // The different rating bars in the layout. Assign the listener to us.
    ((RatingBar)findViewById(R.id.rbOne)).setOnRatingBarChangeListener(this);
    ((RatingBar)findViewById(R.id.rbTwo)).setOnRatingBarChangeListener(this);
    }

    @Override
    public void onRatingChanged(RatingBar ratingBar, float rating,
    boolean fromUser) {
    // getNumStars
    // Returns the number of stars shown.
    final int numStars = ratingBar.getNumStars();
    ratingText.setText(" 欢迎程度 " + rating + "/" + numStars);
    if (indicatorRatingBar.getNumStars() != numStars) {
    indicatorRatingBar.setNumStars(numStars);
    smallRatingBar.setNumStars(numStars);
    }
    // getRating
    // Gets the current rating 评级(number of stars filled).
    if (indicatorRatingBar.getRating() != rating) {
    Log.d("sxp","rating " + rating);
    indicatorRatingBar.setRating(rating);
    smallRatingBar.setRating(rating);
    }
    // getStepSize
    // Gets the step size of this rating bar.
    final float ratingBarStepSize = ratingBar.getStepSize();
    if (indicatorRatingBar.getStepSize() != ratingBarStepSize) {
    Log.d("sxp","ratingBarStepSize " + ratingBarStepSize);
    indicatorRatingBar.setStepSize(ratingBarStepSize);
    smallRatingBar.setStepSize(ratingBarStepSize);
    }
    }
    }

    XML文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical"
    android:paddingLeft
    ="10dip"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content">
    <RatingBar android:id="@+id/rbOne"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:numStars
    ="3"
    android:rating
    ="2.5" />
    <RatingBar android:id="@+id/rbTwo"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:numStars
    ="5"
    android:rating
    ="2.25" />
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height
    ="wrap_content"
    android:layout_marginTop
    ="10dip">

    <TextView android:id="@+id/textView"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content" />

    <RatingBar android:id="@+id/rbThree"
    style
    ="?android:attr/ratingBarStyleSmall"
    android:layout_marginLeft
    ="5dip"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_gravity
    ="center_vertical" />

    </LinearLayout>
    <RatingBar android:id="@+id/rbFour"
    style
    ="?android:attr/ratingBarStyleIndicator"
    android:layout_marginLeft
    ="5dip"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_gravity
    ="center_vertical" />

    </LinearLayout>

    运行效果;


     

  • 相关阅读:
    胖子哥的大数据之路(12)-三张图告诉你大数据安全方案设计
    Building the Unstructured Data Warehouse: Architecture, Analysis, and Design
    Hadoop专业解决方案-第3章:MapReduce处理数据
    胖子哥的大数据之路(11)-我看Intel&&Cloudera的合作
    胖子哥的大数据之路(10)- 基于Hive构建数据仓库实例
    胖子哥的大数据之路(9)-数据仓库金融行业数据逻辑模型FS-LDM
    胖子哥的大数据之路(8)- 数据仓库命名规范
    胖子哥的大数据之路(7)- 传统企业切入核心or外围
    dos 打开计算机管理
    C# SQLite数据库
  • 原文地址:https://www.cnblogs.com/itblog/p/7236624.html
Copyright © 2020-2023  润新知