SeekBar和RatingBar的基本使用方法

SeekBar:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测试SeekBar"
/>
<SeekBar
android:id="@+id/seekbarId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/> </LinearLayout>
MainActivity.java:
package mars.seekbar; import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar; public class MainActivity extends Activity {
/** Called when the activity is first created. */
private SeekBar seekBar = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
seekBar = (SeekBar)findViewById(R.id.seekbarId) ;
//设置该进度条的最大值
seekBar.setMax(100);
seekBar.setOnSeekBarChangeListener(new SeekBarListener());
}
//定义一个监听器,该监听器负责监听进度条状态的改变
private class SeekBarListener implements SeekBar.OnSeekBarChangeListener{
//当进度条的进度发生变化时,会调用该方法
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
System.out.println(progress);
}
//当用户开始滑动滑块时,调用该方法
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
System.out.println("start--->" + seekBar.getProgress());
}
//当用户结束对滑块的滑动时,调用该方法
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
System.out.println("stop--->" + seekBar.getProgress());
} }
}
RatingBar:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<RatingBar
android:id="@+id/ratingbarId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numStars="5"
android:stepSize="1.0"
/>
</LinearLayout>
MainActivity.java:
package mars.ratingbar; import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar; public class MainActivity extends Activity {
/** Called when the activity is first created. */
private RatingBar ratingBar = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ratingBar = (RatingBar)findViewById(R.id.ratingbarId);
ratingBar.setOnRatingBarChangeListener(new RatingBarListener());
} private class RatingBarListener implements RatingBar.OnRatingBarChangeListener{ @Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
System.out.println("rating--->" + rating);
}
}
}
如下图:

SeekBar和RatingBar的基本使用方法的更多相关文章
- SeekBar和RatingBar
今天在看一个音乐播放器的源代码时候用到了SeekBar,就翻出来mars老师的视频复习了一下,然后综合使用了一下. 首先先看下运行效果: 下来我们看看布局文件的设计: main.xml: < ...
- android学习---SeekBar和RatingBar
SeekBar 拖动条:拖动条和滚动栏类似,当是拖动条能够拖动滑块改变进度 RatingBar 星级评分条:星级评分条与拖动条相似 SeekBar特有的xml属性 android:thumb 指 ...
- 二、Android应用的界面编程(六)ProgressBar及其子类[SeekBar、RatingBar]er
通常用于向用户显示某个耗时操作完成的百分比.Android支持几种风格的进度条,通过style属性可以为ProgressBar指定风格.该属性支持如下几个属性值. # @android:style/W ...
- Android学习笔记(九) SeekBar和RatingBar
一.SeekBar的主要属性 -max -progress -secondaryProgress 二.onSeekBarChangeListener -onProgressChanged(SeekBa ...
- ProgressBar(进度条)、SeekBar(拖动条)与星级评分条(RatingBar)
1.ProgressBar(进度条) (1)介绍 (2)常用属性 (3)xml代码 <ProgressBar android:id="@+id/progressBar2" s ...
- Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar
原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...
- ProgressBar、RatingBar和Spinner控件
1.ProgressBar.SeekBar与RatingBar控件 ProgressBar控件,也就是我们通常的进度条控件,可以显示加载的进度等.SeekBar控件,滑块控件,可以根据用户的需要动态为 ...
- android学习笔记九——RatingBar
RatingBar==>星级评分条 RatingBar和SeekBar十分相似,它们甚至有相同的父类:AbsSeekBar.两者都允许用户通过拖动来改变进度: 两者最大的区别在于RatingBa ...
- SeekBar拖动条控件
SeekBar拖动条控件 一.简介 1. 二.SeekBar拖动条控件使用方法 1.创建SeekBar控件 <SeekBar android:id="@+id/SeekBar1&quo ...
随机推荐
- QLabel设置伙伴关系和快捷键(Alt+首字母)
Qlabe中设置伙伴关系是使用Setbuddy函数: Qlabel.Setbuddy(QLineEdit) #将Qlabel和QLineEdit之间设置伙伴关系 另外,需要配合热键(快捷键)进行使用, ...
- Spring Boot JPA 使用教程
JPA 是 Spring Boot 官方推荐的数据库访问组件,其充分体现了面向对象编程思想,有点像 asp.net 的 EFCore.JPA 也是众多 ORM 的抽象. 从本系列开始,都需要用到 my ...
- http协议学习 —— post请求方法提交application/x-www-form-urlencoded类型的数据格式
先推荐一篇很不错的文章:https://imququ.com/post/four-ways-to-post-data-in-http.html 说一下,如果是自己编写底层,那么要注意了,不能只有提交数 ...
- pandas help
1. read_csv read_csv方法定义: pandas.read_csv(filepath_or_buffer, sep=', ', delimiter=None, header='infe ...
- Python - 同时运行两个以上的脚本
在c.py中 import os os.system("python a.py") os.system("python b.py")
- 分布式应用监控:SkyWalking 快速接入实践
分布式应用,会存在各种问题.而要解决这些难题,除了要应用自己做一些监控埋点外,还应该有一些外围的系统进行主动探测,主动发现. APM工具就是干这活的,SkyWalking 是国人开源的一款优秀的APM ...
- 2020.02.28 Linux 命令
Cat 语法格式 cat [-AbeEnstTuv] [--help] [--version] fileName 参数说明: -n 或 --number:由 1 开始对所有输出的行数编号. -b ...
- 导出EXCEL设置单元格格式
怎么设置导出的EXCEL文件的列格式 如何设置导出的EXCEL文件的列格式在office的EXCEL中我们可以在一个EXCEL文件中,选中一列再点击鼠标右键,选择设置单元格格式,可以将这一列设为文本格 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:偏移列
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- idea 编译maven
参考:https://blog.csdn.net/yye894817571/article/details/71681891