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