您的位置:首页 > 产品设计 > UI/UE

Android UI控件详解-SeekBar(拖动条)

2014-04-08 16:33 459 查看
xml布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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:secondaryProgress="70"拖动条的次要进度是70,就是默认的进度是70,
       android:progress="30" 拖动条的进度是30,就是拖动条默认停止在30的这个位置
    -->
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="30"
android:secondaryProgress="70" />

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekbar" />

<TextView
android:id="@+id/tv12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv1" />

</RelativeLayout>
源代码
package com.bdqn.seekbar;

import android.os.Bundle;
import android.app.Activity;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
/**
 *
 * @author TXF
 *
 * SeekBar(拖动条)
 */
public class MainActivity extends Activity {
private SeekBar msb;
private TextView mtv1;
private TextView mtv2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
msb = (SeekBar) findViewById(R.id.seekbar);
mtv1 = (TextView) findViewById(R.id.tv1);
mtv2 = (TextView) findViewById(R.id.tv12);
// 设置拖动条改变监听器
msb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
// 停止拖动的时候调用
@Override
public void onStopTrackingTouch(SeekBar arg0) {
mtv1.setText("停止调节");
}

// 开始拖动时调用
@Override
public void onStartTrackingTouch(SeekBar arg0) {
mtv1.setText("开始调节");

}

// 显示的是当前的进度
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
mtv2.setText("当前的进度是:" + arg1);
}
});
}

}
效果图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ui 控件 SeekBar拖动条