展会信息港展会大全

SeekBar 拖动条 滑动条 改变并显示当前进度的拖动条例子
来源:互联网   发布日期:2015-10-03 11:14:04   浏览:2149次  

导读:SeekBar可以作为音乐播放器的进度指示和调整工具,音量调整工具等,SeekBar是ProgressBar的一个子类,下面我们用一个可以改变并显示当前进度的拖动条例子来演示一下它的使用:1、main.xml ?xml version=1.0......

SeekBar可以作为音乐播放器的进度指示和调整工具,音量调整工具等,SeekBar是ProgressBar的一个子类,下面我们用一个可以改变并显示当前进度的拖动条例子来演示一下它的使用:

1、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/SeekBar01" android:layout_width="fill_parent" android:layout_height="wrap_content">

</seekbar>

<textview android:id="@+id/TextView01" android:textsize="25sp" android:layout_width="fill_parent" android:layout_height="wrap_content">

</textview>

</linearlayout>

2、java:

package android.basic.lesson11;

import android.app.Activity;

import android.os.Bundle;

import android.widget.SeekBar;

import android.widget.SeekBar.OnSeekBarChangeListener;

import android.widget.TextView;

import android.widget.Toast;

public class MainHelloSeekBar extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//找到拖动条和文本框

final SeekBar sb = (SeekBar) findViewById(R.id.SeekBar01);

final TextView tv1 = (TextView) findViewById(R.id.TextView01);

//设置拖动条的初始值和文本框的初始值

sb.setMax(100);

sb.setProgress(30);

tv1.setText("当前进度:" + sb.getProgress());

//设置拖动条改变监听器

OnSeekBarChangeListener osbcl = new OnSeekBarChangeListener() {

@Override

public void onProgressChanged(SeekBar seekBar, int progress,

boolean fromUser) {

tv1.setText("当前进度:" + sb.getProgress());

Toast.makeText(getApplicationContext(), "onProgressChanged",

Toast.LENGTH_SHORT).show();

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

Toast.makeText(getApplicationContext(), "onStartTrackingTouch",

Toast.LENGTH_SHORT).show();

}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

Toast.makeText(getApplicationContext(), "onStopTrackingTouch",

Toast.LENGTH_SHORT).show();

}

};

//为拖动条绑定监听器

sb.setOnSeekBarChangeListener(osbcl);

}

}

3、运行程序:

赞助本站

人工智能实验室

相关热词: 拖动条

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港