当前位置:   article > 正文

直播app系统源码,Android的进度条与拖动条_android pk进度条

android pk进度条

直播app系统源码,Android的进度条与拖动条
一、进度条

public class MainActivity extends Activity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// 找到控件
		final ProgressBar bigProgressBar = (ProgressBar) findViewById(R.id.bigprogressBar);
		final ProgressBar smallProgressBar = (ProgressBar) findViewById(R.id.smallprogressBar);
		final TextView tv_progress1 = (TextView) findViewById(R.id.tv_progress1);
		final TextView tv_progress2 = (TextView) findViewById(R.id.tv_progress2);
 
		// 匿名内部类实现按钮点击事件,开始加载
		findViewById(R.id.btn_load).setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				start(bigProgressBar, tv_progress1);
				start(smallProgressBar, tv_progress2);
			}
		});
	}
 
	// 进度条开始变化的方法
	public void start(final ProgressBar progressBar, final TextView textView) {
		// 耗时任务放在子线程种进行
		new Thread() {
			private int nowProgress;
			private int maxProgress;
 
			public void run() {
				// 得到进度条当前的值
				nowProgress = progressBar.getProgress();
				// 得到进度条最大值
				maxProgress = progressBar.getMax();
				// 当当前进度小于最大进度值时
				while (nowProgress < maxProgress) {
					nowProgress++;
					progressBar.setProgress(nowProgress);
					// 表示在UI线程种更新TextView因为子线程不能更新UI
					runOnUiThread(new Runnable() {
 
						@Override
						public void run() {
							// 设置TextView的内容
							textView.setText(nowProgress + "/" + maxProgress);
						}
					});
					try {
						// 延时模拟加载进度
						Thread.sleep(50);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			};
		}.start();
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

二、拖动条

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// 找到SeekBar
		SeekBar seekBar = (SeekBar) findViewById(R.id.seekbar);
		// 获取音量管理器
		audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
		// 获取当前音乐音量的值 STREAM_MUSIC
		int index = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		// 获取音乐音量的最大值
		int max = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		// 设置拖动条当前值
		seekBar.setProgress(index);
		// 设置拖动条的最大值
		seekBar.setMax(max);
 
		seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
 
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// 拖动停止时调用
			}
 
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// 拖动开始时调用
 
			}
 
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				// 拖动改变时调用
				// 获取seeKbar的当前值
				int seekBarvalue = seekBar.getProgress();
				// 设置音量大小,并在UI上显示 AudioManager.FLAG_SHOW_UI
				audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, seekBarvalue, AudioManager.FLAG_SHOW_UI);
			}
		});
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

以上就是 直播app系统源码,Android的进度条与拖动条,更多内容欢迎关注之后的文章

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/804448
推荐阅读
相关标签
  

闽ICP备14008679号