Android開發(fā)手冊(cè)SeekBar拖動(dòng)條使用實(shí)例
??實(shí)踐過程
??常用屬性
因?yàn)镾eekbar繼承自ProgressBar,所以ProgressBar支持的XML屬性SeekBar都適用。
【android:max="100"】:設(shè)置該進(jìn)度條的最大值
【android:progress="50"】:設(shè)置該進(jìn)度條的已完成進(jìn)度值
【android:progressDrawable="@drawable/icon_xinsui"】:自定義drawable顯示
【android:secondaryProgress="50"】:定義二級(jí)進(jìn)度值,值介于0到max。該進(jìn)度在主進(jìn)度和背景之間。比如用于網(wǎng)絡(luò)播放視頻時(shí),二級(jí)進(jìn)度用于表示緩沖進(jìn)度,主進(jìn)度用于表示播放進(jìn)度。
【android:splitTrack="false"】:設(shè)置進(jìn)度條的滑塊圖片
【android:thumb="@drawable/icon_xinsui"】:滑塊底部 背景樣式 (false為透明 )
公共方法總共有14個(gè),小空直接亮個(gè)截圖
??基本使用
Java版
<TextView android:id="@+id/tvProgress" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="數(shù)值范圍0~100之間,當(dāng)前值:30" android:textSize="20sp" /> <SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:progress="30" />
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tvProgress.setText("數(shù)值范圍0~100之間,當(dāng)前值:"+progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } });
Kotlin版
seekBar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { tvProgress.setText("數(shù)值范圍0~100之間,當(dāng)前值:$progress") } override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} })
然后使用Progressbar的屬性indeterminateDrawable指定即可。
??自定義樣式
這是系統(tǒng)自帶的一個(gè)對(duì)話框進(jìn)度條,樣式美觀度不敢恭維。
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bar); ProgressDialog pb = new ProgressDialog(this); pb.setMax(100); //點(diǎn)擊外部是否可以被取消 pb.setCancelable(true); //設(shè)置標(biāo)題 pb.setTitle("下載對(duì)話框"); //設(shè)置中間文本內(nèi)容 pb.setMessage("正在下載中...."); pb.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pb.show(); //在show后調(diào)用 pb.setProgress(50); }
監(jiān)聽方法 onStartTrackingTouch:當(dāng)開始滑動(dòng)滑塊時(shí),會(huì)執(zhí)行該方法下的代碼
不管哪個(gè)平臺(tái)系統(tǒng)樣式都無法滿足多樣的市場(chǎng)需求和審美需求,自定義樣式就是每個(gè)平臺(tái)都具有的功能。
<SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:progress="30" android:progressDrawable="@drawable/seekbar_one" android:thumb="@drawable/icon_xinsui" /> <SeekBar android:id="@+id/seekBarTwo" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:progress="30" android:progressDrawable="@drawable/seekbar_two" android:thumb="@drawable/icon_xinsui" />
seekbar_one.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <solid android:color="#33AADD" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <solid android:color="#3CC4C4" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <solid android:color="#00ff00" /> </shape> </clip> </item> </layer-list>
seekbar_two.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <corners android:radius="5dp"/> </shape> <!-- 背景顏色--> <color android:color="#CCCCCC"/> </item> <item android:id="@android:id/progress"> <clip android:clipOrientation="horizontal" android:gravity="left"> <shape> <corners android:radius="5dp"/> <!-- 開始顏色,中途顏色,最后顏色--> <gradient android:startColor="#00FF00" android:centerColor="#0000FF" android:endColor="#FF0000"/> </shape> </clip> </item> </layer-list>
同理thumb其實(shí)也是可以自定義的,只不過這個(gè)通常美工給個(gè)圖就搞定了,如果是動(dòng)態(tài)整個(gè)drawable動(dòng)畫即可。
除此以外,通常我們還會(huì)遇見雙向選擇的滑動(dòng)條,比如購物類App選擇價(jià)格區(qū)間的時(shí)候。
可參考:
http://www.dbjr.com.cn/article/250882.htm
http://www.dbjr.com.cn/article/250876.htm
以上就是Android開發(fā)手冊(cè)SeekBar拖動(dòng)條使用實(shí)例的詳細(xì)內(nèi)容,更多關(guān)于Android開發(fā)SeekBar拖動(dòng)條的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Android SeekBar控制視頻播放進(jìn)度實(shí)現(xiàn)過程講解
- Android?SeekBar充當(dāng)Progress實(shí)現(xiàn)兔兔進(jìn)度條Plus
- Android開發(fā)雙向滑動(dòng)選擇器范圍SeekBar實(shí)現(xiàn)
- Android開發(fā)自定義雙向SeekBar拖動(dòng)條控件
- Android通過SeekBar調(diào)節(jié)布局背景顏色
- Android自定義SeekBar實(shí)現(xiàn)滑動(dòng)驗(yàn)證且不可點(diǎn)擊
- Android SeekBar實(shí)現(xiàn)平滑滾動(dòng)
- Android SeekBar在刷新使用中需要注意的問題
相關(guān)文章
Android App中實(shí)現(xiàn)可以雙擊放大和縮小圖片功能的實(shí)例
這篇文章主要介紹了Android App中實(shí)現(xiàn)可以雙擊放大和縮小圖片功能的實(shí)例,文中的例子不能做到逐級(jí)放大但可以做到邊界控制和以觸摸點(diǎn)為中心進(jìn)行放大,需要的朋友可以參考下2016-03-03Android 使用AsyncTask實(shí)現(xiàn)斷點(diǎn)續(xù)傳
這篇文章主要介紹了Android 使用AsyncTask實(shí)現(xiàn)斷點(diǎn)續(xù)傳的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-05-05Android使用AndroidUtilCode實(shí)現(xiàn)多語言
這篇文章主要為大家介紹了Android使用AndroidUtilCode實(shí)現(xiàn)多語言示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android 獲取未安裝的APK圖標(biāo)、版本號(hào)、包名等信息方法
下面小編就為大家分享一篇Android 獲取未安裝的APK圖標(biāo)、版本號(hào)、包名等信息方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2018-01-01Android編程實(shí)現(xiàn)Toast只顯示最后一條的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)Toast只顯示最后一條的方法,結(jié)合實(shí)例形式總結(jié)了Toast只顯示最后一條的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-08-08Android跳轉(zhuǎn)到通訊錄獲取用戶名稱和手機(jī)號(hào)碼的實(shí)現(xiàn)思路
這篇文章主要介紹了Android跳轉(zhuǎn)到通訊錄獲取用戶名稱和手機(jī)號(hào)碼的實(shí)現(xiàn)思路,當(dāng)用戶點(diǎn)擊跳轉(zhuǎn)到通訊錄界面 并取通訊錄姓名和手機(jī)號(hào)碼 ,實(shí)現(xiàn)代碼簡(jiǎn)單易懂,非常不錯(cuò)感興趣的朋友一起看看吧2016-10-10Android開發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法
這篇文章主要介紹了Android開發(fā)基礎(chǔ)之創(chuàng)建啟動(dòng)界面Splash Screen的方法,以實(shí)例形式較為詳細(xì)的分析了Android定制啟動(dòng)界面的布局及功能實(shí)現(xiàn)相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10