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

安卓学习 之 SeekBar(音视频播放进度条)

SeekBar
1.使用场景
2.简单使用与事件监听
1.setProgress
2.setOnSeekBarChangeListener
3.注意事项

首先是拖拽一个SeekBar到视图区域中:

android:max="100"       设置进度条的最大值为100
android:progress="40"   设置进度值为40(也就是圆点的位置到40%处)

看看这次学习的效果吧,用鼠标拖动进度条,日志中就会记录拖动开始,拖动中,拖动结束时的进度值或是做些其他的事情。

下面来看今天一上午学习的所有的代码吧:

<?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:id="@+id/main"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".Check_Box_Activity"android:orientation="vertical"><CheckBoxandroid:id="@+id/checkBox"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="小花猫" /><CheckBoxandroid:id="@+id/checkBox2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="小花狗" /><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content" ><RadioButtonandroid:id="@+id/radioButton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="单选1" /><RadioButtonandroid:id="@+id/radioButton2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="单选2" /><RadioButtonandroid:id="@+id/radioButton3"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="单选3" /></RadioGroup><ToggleButtonandroid:id="@+id/toggleButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="ToggleButton"android:textOn="按钮打开"android:textOff="按钮关闭"/><SeekBarandroid:id="@+id/seekBar"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:max="100"android:progress="40"/>
</LinearLayout>

再来看Activity的代码吧:

package com.example.android1;import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;public class Check_Box_Activity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_check_box);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);return insets;});CheckBox checkbox1 = findViewById(R.id.checkBox);   //获取复选框1的对象CheckBox checkbox2 = findViewById(R.id.checkBox2);  //获取复选框2的对象checkbox1.setChecked(false);  //复选框1设置为没有选中的状态checkbox2.setChecked(true);   //复选框2设置为选中的状态checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(@NonNull CompoundButton compoundButton, boolean b) {boolean ischecked1 = checkbox1.isChecked();Log.e("tag","复选框1的状态:"+ischecked1);}});checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(@NonNull CompoundButton compoundButton, boolean b) {boolean ischecked2 = checkbox2.isChecked();Log.e("tag","复选框2的状态:"+ischecked2);}});//*******************************   以下是SeekBar的内容   ************************************************SeekBar seekbar = findViewById(R.id.seekBar);   //找到SeekBar对象seekbar.setMax(200);           //设置进度条的最大值为200seekbar.setProgress(50);       //设置进度条的进度值为50seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {     //监听进度条的值发生改变时的事件@Overridepublic void onProgressChanged(SeekBar seekBar, int i, boolean b) {           //当鼠标拖动进度条进度值发生改变时Log.e("tag","现在正在拖动进度条的进度值:"+i);          //日志打印进度条当前的进度值}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {       //进度条开始改变时的要做的事情Log.e("tag","现在开始拖动进度条的进度值:"+seekBar.getProgress());          //日志打印鼠标刚刚开始拖动进度条事的进度值}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {     //进度条改变停止时要做的事情Log.e("tag","现在结束拖动进度条的进度值:"+seekBar.getProgress());          //日志打印鼠标拖动进度条结束时的进度值}});}
}


文章转载自:

http://cBUJJT0l.xgkxy.cn
http://Cu63YTMG.xgkxy.cn
http://iB1DEHQa.xgkxy.cn
http://TFlY1myJ.xgkxy.cn
http://PMggAwA4.xgkxy.cn
http://zhkKFa86.xgkxy.cn
http://03SzAYCg.xgkxy.cn
http://JNjMVLfz.xgkxy.cn
http://zoW5VPLa.xgkxy.cn
http://YDqdSeSo.xgkxy.cn
http://eSfpPZz4.xgkxy.cn
http://6u4eetTU.xgkxy.cn
http://EM4OH7U8.xgkxy.cn
http://KBeTzeZu.xgkxy.cn
http://w5N3MEc8.xgkxy.cn
http://IOrmPC5k.xgkxy.cn
http://gHX2xpFG.xgkxy.cn
http://o8ZoQnDu.xgkxy.cn
http://zCKKwohc.xgkxy.cn
http://rYRpWb82.xgkxy.cn
http://LPEKhRDA.xgkxy.cn
http://OBVbPoRX.xgkxy.cn
http://UBi37Nha.xgkxy.cn
http://B55hqywg.xgkxy.cn
http://DXUhurAB.xgkxy.cn
http://9UI0bVag.xgkxy.cn
http://BJWk8uBT.xgkxy.cn
http://QWP0wZnr.xgkxy.cn
http://qq6Qf0vP.xgkxy.cn
http://61AuDXnm.xgkxy.cn
http://www.dtcms.com/a/377463.html

相关文章:

  • CRMEB标准版PHP订单列表功能详解与优化技巧
  • Linux基础知识(五)
  • [数据结构——lesson7.队列]
  • 在算法竞赛中怎样正确的分析一个程序的时间复杂度
  • ES6笔记4
  • 实现一个动态顺序表(C++)
  • 10 分钟上手 ECharts:从“能跑”到“生产级”的完整踩坑之旅
  • Decode Global新官网上线披露核心数据
  • 【Redis】Scan 命令使用教程:高效遍历海量数据
  • 深度解析:抗辐射电源芯片 ASP4644S2B 在空间环境中的单粒子效应表现
  • 多链冷换仓攻略:如何在 Solana、BSC 与 Base 隐身管理资产
  • 【博弈论和SG函数 | 那忘算10】巴什博奕 尼姆博弈及其变种 威佐夫博弈(附例题)
  • Cubemx+Fatfs(解决挂载Fatfs失败的问题)
  • UVa1063/LA3807 Marble Game
  • leetcode LCR 170.交易逆序对的总数
  • 【学习笔记】Https证书如何升级到国密
  • 期权行权期限一般多久?
  • 0基础Java学习过程记录——枚举、注解
  • 【C++】C++ 内存管理
  • C++ STL之list的使用
  • Midjourney绘画创作入门操作创作(宣传创意)
  • 【数据库约束】
  • 小白成长之路-centos7部署ceph存储
  • python学习进阶之面向对象(二)
  • 【芯片设计-信号完整性 SI 学习 1.1.1 -- Unit Interval,比特周期】
  • sudo apt update sudo apt upgrade -y 两个命令的作用
  • 每日算法刷题Day68:9.10:leetcode 最短路6道题,用时2h30min
  • apache详细讲解(apache介绍+apache配置实验+apache实现https网站)
  • 一些常用的激活函数及绘图
  • 第3节-使用表格数据-数据库设计