SeekBar拖動條的應(yīng)用實例
本文實例為大家分享了SeekBar拖動條的應(yīng)用代碼,供大家參考,具體內(nèi)容如下
目標(biāo)效果
在該頁面中放一個拖動條的狀態(tài)提示信息,一個拖動條以及一個顯示拖動條值的信息。當(dāng)我們點擊拖動條時,在狀態(tài)欄顯示:正在拖動,并顯示此時拖動條的值;當(dāng)停止點擊拖動條的時候,狀態(tài)顯示:停止拖動。
目標(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)前拖動條的狀態(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>
動作響應(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);
//為拖動條添加事件監(jiān)聽
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
//當(dāng)檢測到拖動條停止滑動時的一個方法
status.setText("停止拖動");
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
//當(dāng)檢測到拖動條開始滑動,第一次滑動
status.setText("開始滑動");
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)
{
//當(dāng)檢測到拖動條開始位置改變的一個方法,其中arg1表示當(dāng)前滑動的values
status.setText("正在滑動");
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使用Item Swipemenulistview實現(xiàn)仿QQ側(cè)滑刪除功能
大家都用過QQ,肯定有人好奇QQ滑動刪除Item的效果是怎樣實現(xiàn)的,其實我們使用Swipemenulistview就可以簡單的實現(xiàn)。這篇文章主要介紹了Android使用ItemSwipemenulistview實現(xiàn)仿QQ側(cè)滑刪除功能,需要的朋友可以參考下2017-02-02
Android Studio使用Profiler來完成內(nèi)存泄漏的定位
這篇文章主要介紹了Android Studio使用Profiler來完成內(nèi)存泄漏的定位,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03
Android 廣播大全 Intent Action 事件詳解
這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識點,本文講解的非常的全面,感興趣的朋友一起看看吧2015-10-10
Android OnCreate()中獲取控件高度與寬度兩種方法詳解
這篇文章主要介紹了Android OnCreate()中獲取控件高度與寬度兩種方法詳解的相關(guān)資料,這里提供了兩種方法,大家可以都看下,需要的朋友可以參考下2016-12-12
android中UIColletionView瀑布流布局實現(xiàn)思路以及封裝的實現(xiàn)
本篇文章主要介紹了android中UIColletionView瀑布流布局實現(xiàn)思路以及封裝的實現(xiàn),具有一定的參考價值,有興趣的可以了解一下。<BR>2017-02-02
Android仿iOS側(cè)滑退出當(dāng)前界面功能
這篇文章主要為大家詳細(xì)介紹了Android仿iOS側(cè)滑退出當(dāng)前界面功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12

