【Android】Android开发实现进度条效果,SeekBar的简单使用。音量,音乐播放进度,视频播放进度等
2024-09-02 05:56:47
作者:程序员小冰,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("结束");
}
});
}
}
好了,教程到此结束。如果此文章帮到了你,欢迎点赞。
最新文章
- logstash 添加nginx日志
- Windows Azure 使用体验
- Android 自定义NumProgressBar
- linux awk命令
- SQL Server 日志清除
- 首次接触Winform前端交互
- POJ 2435Navigating the City(bfs)
- Spring 定时任务 quartz的配置
- 【转】Android 平台下使用 i2c-tools
- C# Out和Ref区别
- c# winform 中的 工具栏自动隐藏 splitter用法 带源码
- 关联A850刷机包 高级电源 时间中心 优化 ROOT 动力 美化 简化
- 如何开发一个微信小程序
- Python练手例子(8)
- 小白的CTF学习之路5——内存的逻辑结构
- Web API 2 自定义默认Identity Table Name
- 426. Convert Binary Search Tree to Sorted Doubly Linked List把bst变成双向链表
- layui表格和弹出框的简单示例
- dialog--not attached to window manager
- AWK 知识库
热门文章
- charles抓取HTTPS设置,详细踩坑版
- VS c# 操作 Microsoft Project mpp 文件 并遍历边关系
- asp.net core 2.1的全局模型验证统一方案
- js数组中如何去除重复值?
- 19、State 状态模式
- Deep learning-based personality recognition from text posts of online social networks 阅读笔记
- DPL,RPL,CPL 之间的联系和区别
- oracle语法查某个字段为空
- 【Spring】看了这篇Spring事务原理,我才知道我对Spring事务的误解有多深!
- ls-remote -h -t git://github.com/adobe-webplatform/eve.git 报错问题