星级评分RatingBar

1、布局文件

<RatingBar
        android:id="@+id/ratingBar1"
        android:numStars="5"
        android:rating="3.5"
        android:isIndicator="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/button1"
        android:text="提交"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

2、在主活动MainActivity中,定义一个RatingBar类的对象

private RatingBar ratingBar;//星级评分条

3、在onCreate()方法中

ratingBar = (RatingBar)findViewById(R.id.ratingBar1);//获取星级评分条
        Button button = (Button)findViewById(R.id.button1);//获取“提交”按钮
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int result = ratingBar.getProgress();//获取进度
                float rating = ratingBar.getRating();//获取星级
                float step = ratingBar.getStepSize();//获取每次至少需改变多少个星级
                Log.i("星级平分条","step="+step+"result"+result+"rating"+rating);
                Toast.makeText(MainActivity.this,"你得到了+"+rating+"颗星星",Toast.LENGTH_SHORT).show();
            }
        });


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值