Android 之 SeekBar用法介绍
拖动条:
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridView" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/font" android:layout_width="match_parent" android:layout_height="300dp" android:ems="10" android:lines="5" android:text="看我大小,别翻眼..." android:inputType="textMultiLine" > <requestFocus /> </EditText> <SeekBar android:id="@+id/seekBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:scrollbarStyle="insideOverlay" android:progress="1" /> </LinearLayout>
主程序入口:
package com.example.advancedview; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; import android.widget.SeekBar; import android.widget.Toast; import android.widget.SeekBar.OnSeekBarChangeListener; /** * SeekBar 功能演示, 拖动来改变字体的大小 * @author Administrator * */ public class SeekBarActivity extends Activity { //声明变量 private SeekBar seekBar; private EditText font; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.seek_bar_layout); font = (EditText) findViewById(R.id.font); seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setOnSeekBarChangeListener(seekListerner); } // 拖动条事件 private OnSeekBarChangeListener seekListerner = new OnSeekBarChangeListener() { // 拖动条停止执行 public void onStopTrackingTouch(SeekBar seekBar) { Toast.makeText(SeekBarActivity.this, "停止了:"+seekBar.getProgress(), 1000).show(); } // 开始执行 public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(SeekBarActivity.this, "开始了:"+seekBar.getProgress(), 1000).show(); } // 拖动中 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { font.setTextSize(progress); // 改变字体的大小 } }; }
相关推荐
zhonglinzhang 2012-06-05
ffnercn 2012-05-06
mpqitmp 2012-03-05
Drabandon 2014-09-30
moira 2013-11-08
najiutan 2013-05-03
qinxu 2012-08-03
Tom天天 2012-04-26
zhaazha 2011-11-03
Nostalgiachild 2011-09-15
小迈 2011-09-06
AndroidGA 2011-09-02
androidty 2011-05-12
virusplayer 2010-12-24
Liuser 2010-10-14
yuemeng0 2010-07-12
冰川孤辰 2010-05-21