android常用UI使用案例:SeekBar
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SeekBar" /> <SeekBar android:id="@+id/seekbar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="50" android:thumb="@drawable/seeker" /> <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
package com.test.androidui; import android.app.Activity; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.widget.SeekBar; import android.widget.TextView; public class MainActivity extends Activity { private SeekBar seekbar = null; private TextView text = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekbar = (SeekBar) super.findViewById(R.id.seekbar); text = (TextView) super.findViewById(R.id.text); // 设置文本可以滚动 text.setMovementMethod(ScrollingMovementMethod.getInstance()); seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImp()); } private class OnSeekBarChangeListenerImp implements SeekBar.OnSeekBarChangeListener { // 触发操作,拖动 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { text.append("正在拖动,当前值:" + seekBar.getProgress() + "\n"); } // 表示进度条刚开始拖动,开始拖动时候触发的操作 public void onStartTrackingTouch(SeekBar seekBar) { text.append("开始拖动,当前值:" + seekBar.getProgress() + "\n"); } // 停止拖动时候 public void onStopTrackingTouch(SeekBar seekBar) { text.append("停止拖动,当前值:" + seekBar.getProgress() + "\n"); } } }