Android中SeekBar拖動(dòng)條控件使用方法詳解
SeekBar拖動(dòng)條控件使用方法,具體內(nèi)容如下
一、簡介
1、

二、SeekBar拖動(dòng)條控件使用方法
1、創(chuàng)建SeekBar控件
<SeekBar android:id="@+id/SeekBar1" android:layout_width="match_parent" android:layout_height="wrap_content" android:progress="30" />
2、添加setOnSeekBarChangeListener監(jiān)聽
seekBar2.setOnSeekBarChangeListener(this);
三、代碼實(shí)例
1、效果圖:

2、代碼
fry.Activity01
package fry;
import com.example.SeekBarDemo1.R;
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 Activity01 extends Activity implements OnSeekBarChangeListener{
private TextView textView1;
private TextView textView2;
private SeekBar seekBar1;
private SeekBar seekBar2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01);
textView1=(TextView) findViewById(R.id.TextView1_seekBar);
textView2=(TextView) findViewById(R.id.TextView2_seekBar);
seekBar1=(SeekBar) findViewById(R.id.SeekBar1);
seekBar2=(SeekBar) findViewById(R.id.SeekBar2);
seekBar1.setOnSeekBarChangeListener(this);
seekBar2.setOnSeekBarChangeListener(this);
}
/*
* onProgressChanged:進(jìn)度條改變事件
* onStartTrackingTouch:進(jìn)度條開始拖動(dòng)事件
* onStopTrackingTouch:進(jìn)度條停止拖動(dòng)事件
* (non-Javadoc)
* @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
Toast.makeText(this, "1111111", Toast.LENGTH_SHORT).show();
textView1.setText("seekBar1當(dāng)前位置:"+progress);
}else{
textView2.setText("seekBar2當(dāng)前位置:"+progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
textView1.setText("seekBar1開始拖動(dòng)");
}else{
textView2.setText("seekBar2開始拖動(dòng):");
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
textView1.setText("seekBar1停止拖動(dòng)");
}else{
textView2.setText("seekBar2停止拖動(dòng):");
}
}
}
/SeekBarDemo1/res/layout/activity01.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/TextView1_seekBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TextView1" /> <TextView android:id="@+id/TextView2_seekBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TextView2" /> <SeekBar android:id="@+id/SeekBar1" android:layout_width="match_parent" android:layout_height="wrap_content" android:progress="30" /> <SeekBar android:id="@+id/SeekBar2" android:layout_width="match_parent" android:layout_height="wrap_content" android:progress="60" /> </LinearLayout>
四、獲得
1、設(shè)置初始進(jìn)度條
android:progress="30"
2、設(shè)置setOnSeekBarChangeListener監(jiān)聽
seekBar1.setOnSeekBarChangeListener(this);
3、onProgressChanged:進(jìn)度條改變事件
4、onStartTrackingTouch:進(jìn)度條開始拖動(dòng)事件
5、onStopTrackingTouch:進(jìn)度條停止拖動(dòng)事件
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)實(shí)現(xiàn)自定義水平滾動(dòng)的容器示例
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)自定義水平滾動(dòng)的容器,涉及Android滾動(dòng)容器的事件響應(yīng)、屬性運(yùn)算與修改相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
Android Studio打包H5網(wǎng)址頁面,封裝成APK
大家好,本篇文章主要講的是Android Studio打包H5網(wǎng)址頁面,封裝成APK,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12
Android ContentProvider查看/讀取手機(jī)聯(lián)系人實(shí)例
本篇文章主要介紹了Android ContentProvider查看/讀取手機(jī)聯(lián)系人實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
Activity實(shí)例詳解之啟動(dòng)activity并返回結(jié)果
這篇文章主要介紹了Activity實(shí)例詳解之啟動(dòng)activity并返回結(jié)果 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
Android 用戶Session管理的設(shè)計(jì)方案
這篇文章主要介紹了Android 用戶Session管理的設(shè)計(jì)方案,需要的朋友可以參考下2017-12-12
Android中TextView自動(dòng)適配文本大小的幾種解決方案
在布局中使用的話,注意按照你最大的設(shè)備來設(shè)置字體大小,這樣在小設(shè)備上回自動(dòng)縮放,下面這篇文章主要給大家介紹了關(guān)于Android中TextView自動(dòng)適配文本大小的幾種解決方案,需要的朋友可以參考下2022-06-06
Android AnalogClock簡單使用方法實(shí)例
這篇文章主要介紹了Android AnalogClock簡單使用方法,結(jié)合實(shí)例形式簡單分析了AnalogClock的布局調(diào)用技巧,需要的朋友可以參考下2016-01-01
Android使用NestedScrollView?內(nèi)嵌RecycleView滑動(dòng)沖突問題解決
這篇文章主要介紹了Android使用NestedScrollView?內(nèi)嵌RecycleView滑動(dòng)沖突問題解決,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下2022-06-06

