本文主要是介绍Android常用控件之:SeekBar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*** Android控件之SeekBar介绍 OnSeekBarChangeListener:拖动进度条发生变化监听接口* * @description:* @author ldm* @date 2016-6-3 上午10:39:22*/
public class SeekBar1 extends Activity implementsSeekBar.OnSeekBarChangeListener {private SeekBar mSeekBar;// 拖动条TextView mProgressText;// 进度提示文字TextView mTrackingText;// 拖动状态提示文字@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_seekbar);initViews();}private void initViews() {mSeekBar = (SeekBar) findViewById(R.id.seek);mSeekBar.setOnSeekBarChangeListener(this);mProgressText = (TextView) findViewById(R.id.progress);mTrackingText = (TextView) findViewById(R.id.tracking);}// 进度长发生改变public void onProgressChanged(SeekBar seekBar, int progress,boolean fromTouch) {mProgressText.setText("当前进度-->" + progress + "是否为用户拖动的滑块-->= "+ fromTouch);}// 开始拖动状态监听public void onStartTrackingTouch(SeekBar seekBar) {mTrackingText.setText("开始拖动");}// 停止拖动状态监听public void onStopTrackingTouch(SeekBar seekBar) {mTrackingText.setText("停止拖动");}
}
—–布局文件—–
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><!-- android:max="100" 进度时大值 --><!-- android:progress="50" 进度条主进度当前值 --><!-- android:secondaryProgress="75" 进度条次进度当前值 --><SeekBar
android:id="@+id/seek"android:layout_width="match_parent"android:layout_height="wrap_content"android:max="100"android:progress="50"android:secondaryProgress="75" /><TextView
android:id="@+id/progress"android:layout_width="match_parent"android:layout_height="wrap_content"android:padding="10dp"android:textSize="16sp" /><TextView
android:id="@+id/tracking"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="16sp" /></LinearLayout>
工作中,系统样式的SeekBar通常不能满足用户的眼球,所以我们可以自定义xml文件来实现SeekBar的style风格。
这篇关于Android常用控件之:SeekBar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!