seekbar的使用(数值拖动框的使用—用于选择数值)
来源:互联网 发布:dos是什么办公软件 编辑:程序博客网 时间:2024/06/01 22:52
用处:可用于视频播放
布局文件:
<?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:id="@+id/textview1" android:layout_width="fill_parent"android:layout_height="wrap_content" /><TextView android:id="@+id/textview2" android:layout_width="fill_parent"android:layout_height="wrap_content" /><SeekBar android:id="@+id/seekbar1" android:layout_width="fill_parent"android:layout_height="wrap_content" android:max="100"android:progress="30"></SeekBar><SeekBar android:id="@+id/seekbar2" android:layout_width="fill_parent"android:layout_height="wrap_content" android:max="100"android:progress="30" android:secondaryProgress="60"></SeekBar></LinearLayout>
代码:
添加监听事件:onseekbarlistener 实现监听:
监听函数:第一个参数表示:bar对象,第二个表示参数。
表示从哪里开始拖动:onstarttrackingtouch()
从哪里结束拖动:onstoptrackingtouch()
package com.example.marvinedittext2;import android.app.Activity;import android.os.Bundle;import android.widget.SeekBar;import android.widget.TextView;import android.widget.SeekBar.OnSeekBarChangeListener;public class Main extends Activity implements OnSeekBarChangeListener {/** Called when the activity is first created. */private TextView textView1, textView2;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);textView1 = (TextView) this.findViewById(R.id.textview1);textView2 = (TextView) this.findViewById(R.id.textview2);SeekBar seekBar1 = (SeekBar) this.findViewById(R.id.seekbar1);SeekBar seekBar2 = (SeekBar) this.findViewById(R.id.seekbar2);seekBar1.setOnSeekBarChangeListener(this);seekBar2.setOnSeekBarChangeListener(this);}// 当滑动滑竿的时候会触发的事件@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubif (seekBar.getId() == R.id.seekbar1) {textView1.setText("seekbar1的当前位置是:" + progress);} else {textView2.setText("seekbar2的当前位置是:" + progress);}}// 表示从哪里开始拖动@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubif (seekBar.getId() == R.id.seekbar1) {textView1.setText("seekbar1开始拖动");} else {textView1.setText("seekbar2开始拖动");}}// 表示从哪里结束拖动@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubif (seekBar.getId() == R.id.seekbar1) {textView1.setText("seekbar1停止拖动");} else {textView1.setText("seekbar2停止拖动");}}}
总结:还是用监听,进行相应的操作。
拓展:判断多个组件用用一个监听的时候,判断到底是哪一个组件,方法是用id进行判断的。在上面的代码有例子。
0 0
- seekbar的使用(数值拖动框的使用—用于选择数值)
- 拖动条SeekBar的使用
- SeekBar拖动条的使用
- SeekBar拖动条的基本使用
- Android开发拖动条SeekBar的使用
- 拖动条SeekBar的简单使用
- 拖动条SeekBar的简单使用
- Android开发拖动条SeekBar的使用
- 使用SeekBar制作可拖动的进度条
- Android开发拖动条SeekBar的使用
- 使用SeekBar制作可拖动的进度条
- Android 拖动条SeekBar的简单使用
- (数值计算方法)matlab的使用
- (数值计算方法)matlab的使用
- 高级控件之拖动条(SeekBar)的使用
- android自定义Seekbar你还将你的拖动数值显示在旁边固定的TextView上么?
- android自定义Seekbar你还将你的拖动数值显示在旁边固定的TextView上么?
- Android入门(37)——第十四章 使用SeekBar制作可拖动的进度条
- mappingResources、mappingLocations、mappingDirectoryLocations、mappingJarLocations
- iframe双滚动条 解决方式 CSS3 overflow-y 属性
- 冒泡排序的交换次数
- tomcat目录解释
- Unity3D性能优化--- 收集整理的一堆
- seekbar的使用(数值拖动框的使用—用于选择数值)
- 黑马程序员_毕向东java基础视频第五天
- 经典面试题目——250M内存处理10G大小的log文件
- Js 获取日期时间
- SQL Server 中 RAISERROR 的用法
- 第十周项目 4 大奖赛计分
- 黑马程序员_毕向东java基础视频第六天
- Java为什么没有C/C++运行快
- 20141103 【 信息安全 】 对称密码体系 —— DES 加密算法