当前位置: 首页 > article >正文

Android 第三十九章 RatingBar

一、属性

  1. android:isIndicator=“false” 此评级栏是否为指示器(用户不可更改)。 默认false 可更改,true 不可更改
  2. android:numStars=“6” 设置星星数量
  3. android:rating=“1” 设置默认评级
  4. android:stepSize=“2” 设置步长

二、示例

class MainActivity : AppCompatActivity() {

    private lateinit var ratingBar: RatingBar

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView()
        initClick()
    }

    private fun initView() {
        ratingBar = findViewById(R.id.ratingBar)
    }

    private fun initClick() {
        ratingBar.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
            Toast.makeText(this, "评级:$rating", Toast.LENGTH_SHORT).show()
        }
    }

}
<?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"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <RatingBar
        android:id="@+id/ratingBar"
        style="?android:attr/ratingBarStyleIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isIndicator="false"
        android:numStars="6"
        android:rating="1"
        android:stepSize="2" />

</LinearLayout>

http://www.kler.cn/news/155695.html

相关文章:

  • SpringMVC常用注解和用法总结
  • leetcode:468. 验证IP地址
  • viple模拟器使用(四):unity模拟器中实现两距离局部最优迷宫算法
  • javaee实验:文件上传及截器的使用
  • 迭代器模式-C++实现
  • Hive 安装部署
  • (11_29)畅捷通的 Serverless 探索实践之路
  • [Java]轻松掌握JDK和CGlib代理的使用技巧,让你的Java程序性能更卓越!
  • C语言实战演练之贪吃蛇游戏
  • 【springboot】启动失败 Failed to start bean ‘webServerStartStop‘
  • Unity安装
  • Python生产者消费者模型
  • Zabbix 6.0 详细基础介绍
  • 充电桩新老国标兼容性分析
  • OpenCvSharp从入门到实践-(06)创建图像
  • 编译原理头歌实验:实验4《算符优先分析法设计与实现》(C语言版)
  • vue el-select封装及使用
  • Prefix-Tuning 论文概述
  • JAVA代码优化:记录日志
  • 使用AOS实现网页动画效果
  • 利用段落检索和生成模型进行开放域问答12.2
  • Spring Initial 脚手架国内镜像地址
  • C/C++学生选课/排课系统[2023-12-3]
  • 保育员个人简历精选7篇
  • C++笔试训练day_1
  • Linux网络之连接跟踪 conntrack
  • gitlab 代码提交账户信息修改
  • “大型”基础模型中幻觉的调查
  • 工程数学笔记 | 傅里叶级数/变换的本质理解
  • 1949-2021年全国31省铁路里程数据