SeekBar拖動(dòng)條的應(yīng)用實(shí)例
本文實(shí)例為大家分享了SeekBar拖動(dòng)條的應(yīng)用代碼,供大家參考,具體內(nèi)容如下
目標(biāo)效果
在該頁面中放一個(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)界面如下所示:



頁面布局
<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)聽
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
//當(dāng)檢測到拖動(dòng)條停止滑動(dòng)時(shí)的一個(gè)方法
status.setText("停止拖動(dòng)");
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
//當(dāng)檢測到拖動(dòng)條開始滑動(dòng),第一次滑動(dòng)
status.setText("開始滑動(dòng)");
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)
{
//當(dāng)檢測到拖動(dòng)條開始位置改變的一個(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;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android實(shí)現(xiàn)widget時(shí)鐘示例分享
這篇文章主要介紹了android實(shí)現(xiàn)widget時(shí)鐘示例,需要的朋友可以參考下2014-03-03
Android 雙擊Back鍵退出應(yīng)用的實(shí)現(xiàn)方法
這篇文章主要介紹了Android 雙擊Back鍵退出應(yīng)用的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10
Android開發(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
Android學(xué)習(xí)之Flux架構(gòu)入門
Flux是Facebook在14年提出的一種Web前端架構(gòu),主要用來處理復(fù)雜的UI邏輯的一致性問題(當(dāng)時(shí)是為了解決Web頁面的消息通知問題)。接下來從其特點(diǎn)和使用上來介紹Flux架構(gòu)。本文主要目的是讓你對Flux的一個(gè)架構(gòu)大體面貌有個(gè)了解。2016-08-08
android端使用openCV實(shí)現(xiàn)車牌檢測
這篇文章主要為大家詳細(xì)介紹了android端使用openCV實(shí)現(xiàn)車牌檢測,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
詳解Android中的ActivityThread和APP啟動(dòng)過程
ActivityThread就是我們常說的主線程或UI線程,ActivityThread的main方法是整個(gè)APP的入口,本篇深入學(xué)習(xí)下ActivityThread,順便了解下APP和Activity的啟動(dòng)過程。2021-06-06

