作者:程序员小冰,GitHub主页:https://github.com/QQ986945193

新浪微博:http://weibo.com/mcxiaobing

首先给大家看一下我们今天这个最终实现的效果图:



当然,这里的进度,是我们手动触摸控制的。截图可能不是很明显。

其实是很简单的,这只是一个android的控件而已,实现方法是,首先

我们在布局中引用seekbar。

<?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"> <SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <TextView
android:id="@+id/tv_sb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="进度条:" />
</LinearLayout>

然后,我们在java代码中实现SeekBar的监听事件。我这里监听事件,就随便打了一下log,当然,在项目中如果用了它,就做适当的事情就可以了。代码也很简单,如下:

package davidseekbarmusicmoredemo.qq986945193.com.davidseekbarmusicmoredemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView; /**
* @author :程序员小冰
* @新浪微博 :http://weibo.com/mcxiaobing
* @GitHub: https://github.com/QQ986945193
* @CSDN博客: http://blog.csdn.net/qq_21376985
* @码云OsChina :http://git.oschina.net/MCXIAOBING
*/
public class MainActivity extends AppCompatActivity {
private TextView tv_sb;
private SeekBar sb; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
} /**
* 初始化控件
*/
private void initView() {
tv_sb = (TextView) findViewById(R.id.tv_sb);
sb = (SeekBar) findViewById(R.id.sb);
//SeekBar的监听事件
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
//监听点击时
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.e("xiaobing", "开始");
tv_sb.setText("开始");
} //监听滑动时
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.e("xiaobing", "变化" + progress);
tv_sb.setText("进度条" + progress);
} //监听停止时
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.d("xiaobing", "结束");
tv_sb.setText("结束");
}
});
}
}

好了,教程到此结束。如果此文章帮到了你,欢迎点赞。

最新文章

  1. logstash 添加nginx日志
  2. Windows Azure 使用体验
  3. Android 自定义NumProgressBar
  4. linux awk命令
  5. SQL Server 日志清除
  6. 首次接触Winform前端交互
  7. POJ 2435Navigating the City(bfs)
  8. Spring 定时任务 quartz的配置
  9. 【转】Android 平台下使用 i2c-tools
  10. C# Out和Ref区别
  11. c# winform 中的 工具栏自动隐藏 splitter用法 带源码
  12. 关联A850刷机包 高级电源 时间中心 优化 ROOT 动力 美化 简化
  13. 如何开发一个微信小程序
  14. Python练手例子(8)
  15. 小白的CTF学习之路5——内存的逻辑结构
  16. Web API 2 自定义默认Identity Table Name
  17. 426. Convert Binary Search Tree to Sorted Doubly Linked List把bst变成双向链表
  18. layui表格和弹出框的简单示例
  19. dialog--not attached to window manager
  20. AWK 知识库

热门文章

  1. charles抓取HTTPS设置,详细踩坑版
  2. VS c# 操作 Microsoft Project mpp 文件 并遍历边关系
  3. asp.net core 2.1的全局模型验证统一方案
  4. js数组中如何去除重复值?
  5. 19、State 状态模式
  6. Deep learning-based personality recognition from text posts of online social networks 阅读笔记
  7. DPL,RPL,CPL 之间的联系和区别
  8. oracle语法查某个字段为空
  9. 【Spring】看了这篇Spring事务原理,我才知道我对Spring事务的误解有多深!
  10. ls-remote -h -t git://github.com/adobe-webplatform/eve.git 报错问题