Android SeekBar實(shí)現(xiàn)滑動(dòng)條效果
本文實(shí)例為大家分享了Android SeekBar實(shí)現(xiàn)滑動(dòng)條效果的具體代碼,供大家參考,具體內(nèi)容如下
SeekBar是ProgressBar的一個(gè)子類(lèi),下面我們用一個(gè)可以改變并顯示當(dāng)前進(jìn)度的拖動(dòng)條例子來(lái)演示一下它的使用:
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="245px"
android:layout_height="25px" android:paddingLeft="16px"
android:paddingRight="15px" android:paddingTop="5px"
android:paddingBottom="5px" android:progress="0" android:max="0"
android:secondaryProgress="0" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:id="@+id/TextView01" />
</LinearLayout>
2、java:
package com.esri.arcgis.sample;
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 AndroidSeekBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 找到拖動(dòng)條和文本框
final SeekBar sb = (SeekBar) findViewById(R.id.SeekBar01);
final TextView tv1 = (TextView) findViewById(R.id.TextView01);
// 設(shè)置拖動(dòng)條的初始值和文本框的初始值
sb.setMax(100);
sb.setProgress(30);
tv1.setText("當(dāng)前進(jìn)度:" + sb.getProgress());
// 設(shè)置拖動(dòng)條改變監(jiān)聽(tīng)器
OnSeekBarChangeListener osbcl = new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
tv1.setText("當(dāng)前進(jìn)度:" + 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();
}
};
// 為拖動(dòng)條綁定監(jiān)聽(tīng)器
sb.setOnSeekBarChangeListener(osbcl);
}
}
3、運(yùn)行程序:


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android傳感器SensorEventListener之加速度傳感器
今天小編就為大家分享一篇關(guān)于Android傳感器SensorEventListener之加速度傳感器,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-02-02
Android 中RecyclerView通用適配器的實(shí)現(xiàn)
這篇文章主要介紹了Android 中RecyclerView通用適配器的實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-03-03
mui.init()與mui.plusReady()區(qū)別和關(guān)系
給大家分享一下在使用MUI進(jìn)行APP開(kāi)發(fā)的時(shí)候,mui.init()與mui.plusReady()區(qū)別以及使用上不同之處。2017-11-11
android實(shí)現(xiàn)微信朋友圈發(fā)布動(dòng)態(tài)功能
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)微信朋友圈發(fā)布動(dòng)態(tài)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
淺談Android單元測(cè)試的作用以及簡(jiǎn)單示例
本篇文章主要介紹了淺談Android單元測(cè)試的作用以及簡(jiǎn)單示例,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08
Android實(shí)時(shí)文件夾創(chuàng)建方法
這篇文章主要介紹了Android實(shí)時(shí)文件夾創(chuàng)建方法,涉及基于Activity實(shí)現(xiàn)文件實(shí)時(shí)查詢(xún)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
Android超清晰6.0權(quán)限申請(qǐng)AndPermission
這篇文章主要介紹了Android超清晰6.0權(quán)限申請(qǐng)AndPermission,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11

