SeekBar拖動(dòng)條的應(yīng)用實(shí)例
本文實(shí)例為大家分享了SeekBar拖動(dòng)條的應(yīng)用代碼,供大家參考,具體內(nèi)容如下
目標(biāo)效果
在該頁(yè)面中放一個(gè)拖動(dòng)條的狀態(tài)提示信息,一個(gè)拖動(dòng)條以及一個(gè)顯示拖動(dòng)條值的信息。當(dāng)我們點(diǎn)擊拖動(dòng)條時(shí),在狀態(tài)欄顯示:正在拖動(dòng),并顯示此時(shí)拖動(dòng)條的值;當(dāng)停止點(diǎn)擊拖動(dòng)條的時(shí)候,狀態(tài)顯示:停止拖動(dòng)。
目標(biāo)界面如下所示:
頁(yè)面布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:background="@drawable/b1" > <TextView android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="我是當(dāng)前拖動(dòng)條的狀態(tài)" android:textColor="#FFFFFF" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:textSize="24dp"/> <SeekBar android:id="@+id/seek" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" /> <TextView android:id="@+id/show_values" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:text="當(dāng)前的值為0" android:textColor="#FFFFFF" android:textSize="24dp"/> </LinearLayout>
動(dòng)作響應(yīng)事件
package com.example.seekbar; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; public class MainActivity extends Activity { TextView status,show; SeekBar seek=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); status=(TextView) findViewById(R.id.status); show=(TextView) findViewById(R.id.show_values); seek=(SeekBar) findViewById(R.id.seek); //為拖動(dòng)條添加事件監(jiān)聽(tīng) seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { //當(dāng)檢測(cè)到拖動(dòng)條停止滑動(dòng)時(shí)的一個(gè)方法 status.setText("停止拖動(dòng)"); } @Override public void onStartTrackingTouch(SeekBar arg0) { //當(dāng)檢測(cè)到拖動(dòng)條開(kāi)始滑動(dòng),第一次滑動(dòng) status.setText("開(kāi)始滑動(dòng)"); } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { //當(dāng)檢測(cè)到拖動(dòng)條開(kāi)始位置改變的一個(gè)方法,其中arg1表示當(dāng)前滑動(dòng)的values status.setText("正在滑動(dòng)"); show.setText("當(dāng)前的值為:"+arg1); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Flutter手勢(shì)密碼的實(shí)現(xiàn)示例(附demo)
本文主要介紹了Flutter手勢(shì)密碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Android使用Item Swipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能
大家都用過(guò)QQ,肯定有人好奇QQ滑動(dòng)刪除Item的效果是怎樣實(shí)現(xiàn)的,其實(shí)我們使用Swipemenulistview就可以簡(jiǎn)單的實(shí)現(xiàn)。這篇文章主要介紹了Android使用ItemSwipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能,需要的朋友可以參考下2017-02-02Android Studio使用Profiler來(lái)完成內(nèi)存泄漏的定位
這篇文章主要介紹了Android Studio使用Profiler來(lái)完成內(nèi)存泄漏的定位,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android 廣播大全 Intent Action 事件詳解
這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識(shí)點(diǎn),本文講解的非常的全面,感興趣的朋友一起看看吧2015-10-10Android OnCreate()中獲取控件高度與寬度兩種方法詳解
這篇文章主要介紹了Android OnCreate()中獲取控件高度與寬度兩種方法詳解的相關(guān)資料,這里提供了兩種方法,大家可以都看下,需要的朋友可以參考下2016-12-12Android5.0 旋轉(zhuǎn)菜單實(shí)例詳解
這篇文章主要介紹了 Android5.0 旋轉(zhuǎn)菜單的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2016-12-12Android仿簡(jiǎn)書(shū)長(zhǎng)按文章生成圖片效果
使用簡(jiǎn)書(shū)APP的同學(xué)都知道,簡(jiǎn)書(shū)有這樣一個(gè)功能;文章頁(yè)長(zhǎng)按內(nèi)容時(shí)底部會(huì)出現(xiàn)一個(gè) 生成圖片分享 的按鈕,點(diǎn)擊之后就可以將當(dāng)前的文章生成一張長(zhǎng)圖片;這張圖片可以保存到本地或分享給好友,同時(shí)還可為圖片設(shè)置成為白和黑兩種風(fēng)格,很有藝術(shù)范2017-03-03android中UIColletionView瀑布流布局實(shí)現(xiàn)思路以及封裝的實(shí)現(xiàn)
本篇文章主要介紹了android中UIColletionView瀑布流布局實(shí)現(xiàn)思路以及封裝的實(shí)現(xiàn),具有一定的參考價(jià)值,有興趣的可以了解一下。<BR>2017-02-02Android仿iOS側(cè)滑退出當(dāng)前界面功能
這篇文章主要為大家詳細(xì)介紹了Android仿iOS側(cè)滑退出當(dāng)前界面功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12