Android seekbar實(shí)現(xiàn)可拖動(dòng)進(jìn)度條
本文實(shí)例為大家分享了Android seekbar實(shí)現(xiàn)可拖動(dòng)進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下
SeekBar通過(guò)滑塊的位置來(lái)標(biāo)識(shí)數(shù)值 允許用戶通過(guò)拖動(dòng)滑塊來(lái)改變進(jìn)度值的大小
控件:SeekBar
兩個(gè)TextView 顯示狀態(tài)
實(shí)現(xiàn)SeekBar.OnSeekBarChangeListener接口 對(duì)事件進(jìn)行監(jiān)聽(tīng)
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"> <SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="50" /> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity:
package com.example.lenovo.seekbar; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.SeekBar; import android.widget.TextView; public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener { private SeekBar seekBar; private TextView tv1; private TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1=findViewById(R.id.tv1); tv2=findViewById(R.id.tv2); seekBar=findViewById(R.id.seekBar); //設(shè)置監(jiān)聽(tīng)器 監(jiān)聽(tīng)數(shù)值改變情況 seekBar.setOnSeekBarChangeListener(this); } //數(shù)值改變 @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv1.setText("正在拖動(dòng)"); tv2.setText("當(dāng)前數(shù)值:"+progress); } //開(kāi)始拖動(dòng) @Override public void onStartTrackingTouch(SeekBar seekBar) { tv1.setText("開(kāi)始拖動(dòng)"); } //停止拖動(dòng) @Override public void onStopTrackingTouch(SeekBar seekBar) { tv1.setText("停止拖動(dòng)"); } }
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 實(shí)現(xiàn)仿QQ拖拽氣泡效果的示例
這篇文章主要介紹了Android 實(shí)現(xiàn)仿QQ拖拽氣泡效果的示例,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-04-04android開(kāi)發(fā)教程之startActivityForResult使用方法
這篇文章主要介紹了android開(kāi)發(fā)教程之startActivityForResult使用方法,需要的朋友可以參考下2014-03-03Android 通知使用權(quán)(NotificationListenerService)的使用
這篇文章主要介紹了Android 通知使用權(quán)(NotificationListenerService)的使用的相關(guān)資料,需要的朋友可以參考下2017-06-06Android開(kāi)發(fā)實(shí)現(xiàn)TextView顯示豐富的文本
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)TextView顯示豐富的文本,涉及Android中TextView的使用技巧,需要的朋友可以參考下2015-12-12Jetpack Compose圖片組件使用實(shí)例詳細(xì)講解
在Compose中,圖片組件主要有兩種,分別是顯示圖標(biāo)的Icon組件和顯示圖片的Image組件,當(dāng)我們顯示一系列的小圖標(biāo)的時(shí)候,我們可以使用Icon組件,當(dāng)顯示圖片時(shí),我們就用專用的Image組件2023-04-04android中WebView和javascript實(shí)現(xiàn)數(shù)據(jù)交互實(shí)例
這篇文章主要介紹了android中WebView和javascript實(shí)現(xiàn)數(shù)據(jù)交互實(shí)例,需要的朋友可以參考下2014-07-07android ItemTouchHelper實(shí)現(xiàn)可拖拽和側(cè)滑的列表的示例代碼
本篇文章主要介紹了ItemTouchHelper實(shí)現(xiàn)可拖拽和側(cè)滑的列表的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02基于Google ML模型開(kāi)發(fā)Android物體檢測(cè)應(yīng)用
ML Kit是Google提供的機(jī)器學(xué)習(xí)SDK,包含了一系列預(yù)訓(xùn)練模型,可以在Android和iOS應(yīng)用中快速添加機(jī)器學(xué)習(xí)功能,本項(xiàng)目基于Google ML模型開(kāi)發(fā)Android物體檢測(cè)應(yīng)用,首先對(duì)圖像中的物體進(jìn)行分類檢測(cè),獲取分類物體的位置區(qū)域,然后結(jié)合圖像標(biāo)記,逐個(gè)獲取單個(gè)物體的標(biāo)簽2024-07-07