拖动条类似于进度条,但是进度条不可以控制。
拖动条可以被用户控制,在SeekBar中要监听3个事件。
分别是:
1.数值的改变(onProgressBar)
2.开始拖动(onStarTrackingTouch)
3.停止拖动(onStopTrackingTouch)
package com.ko8e;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
public class MyActivity extends Activity {
/** Called when the activity is first created. */
TextView textView1 = null;
TextView textView2 = null;
SeekBar sb = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView1 = (TextView) findViewById(R.id.textView1);
textView2 = (TextView) findViewById(R.id.textView2);
sb = (SeekBar) findViewById(R.id.seekBar);
textView1.setText("初始值:" + sb.getProgress());
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(), "onStopTrackingTouch", Toast.LENGTH_SHORT).show();
}
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(getApplicationContext(), "onStartTrackingTouch", Toast.LENGTH_SHORT).show();
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
textView2.setText("当前进度值:" + sb.getProgress());
Toast.makeText(getApplicationContext(), "onProgressChanged", Toast.LENGTH_SHORT).show();
}
});
}
}
main.xml
<?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"
>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="30"
android:secondaryProgress="70"
/>
<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"
/>
</LinearLayout>
分享到:
相关推荐
CircularSeekBar用于Android的定制圆形SeekBar(圆形,半圆形和椭圆形)
seekbar的一个扩展版本
先来上个效果图: 当滑动时:数值显示,滑动停止时显示数字,使用FrameLayout结合SeekBar。 首先我们看看。 Layout: <?xml version=1.0 encoding=utf-... android:id=@+id/wrapper_seekbar_indicator android:la
Android基础控件——SeekBar的使用、仿淘宝滑动验证
Android双向seekbar(带刻度),自定义view,控制上限和下限
一个横竖向都可以的SeekBar 控件
自定义控件,替代android自带的seekbar功能,有需要的朋友自行下载。
android seekbar 双向选择的进度条
SeekBar是进度条。本篇文章介绍了Android控件之SeekBar的使用,SeekBar的应用非常广,比如用来显示音量条、播放进度条,有水平显示也有垂直显示,有兴趣的可以了解一下。
android双向SeekBar滑动控件,有需要的可以看看
由于公司项目需要,需要展示一个用于选择金额的标尺控件,因此参照网上的一些示例,编写了一个控件,该控件能够调整字体颜色和线条颜色,可以规定每多少单位出现一个空格,可以选择该控件进行最大值最小值之间的单选...
ArcSeekBar 弯曲的Android SeekBar
[Android实例] Android 竖着的SeekBar 需要的请下载 对于现阶段的Android开发而言,技术深度很大一部分就体现在对Android系统底层的理解上。只有理解了底层的运作,我们才能更全面的掌握应用的行为、解决更多疑难...
这个是在公司项目中准备使用的一个控件,本准备直接在网上搜一个用,可惜找到的很多都是 ProgressBar,并不具备拖拽功能,于是自己动手实现了一个,其功能和特性均仿照 SeekBar 进行设计。 效果预览 支持的特性 [x...
SeekBar是Android开发中常用的一个控件,用于实现滑动条功能。然而,传统的SeekBar是水平方向的,有时候需要根据具体需求将其改为竖直方向。本项目旨在开发一个基于Android平台的竖着的SeekBar控件,以满足用户在...
seekbar Android 开发 标尺 拖动,不可多得Android开发利器
1:首先在布局文件中添加seekbar控件 <SeekBar android:id="@+id/seek" android:layout_width="300px" android:layout_height="wrap_content" android:max="100" android:progress="0" android:...
可自定义样式、竖立的SeekBar控件源码。Android前端。
SeekBar控件在开发中还是比较常见的,比如音视频进度、音量调节等,但是原生控件有时还不能满足我们的需求,今天就来学习一下如何自定义SeekBar控件,本文主要实现了一个带文字指示器效果的SeekBar控件 看下最终效果...