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);
}
});
}
}
效果图
<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);
}
});
}
}
效果图
相关文章推荐
- Android中SeekBar拖动条控件使用方法详解
- Android-高级UI控件_SeekBar拖动条
- 【Android 开发】:UI控件之拖动条控件 SeekBar的使用方法
- Android UI控件详解-GridView(网格视图)
- ANDROID L——Material Design详解(UI控件)
- Android UI开发详解之模板控件的复用
- ANDROID L——Material Design详解(UI控件)
- Android UI,界面辅助设置工具,可随意拖动控件,比google官方提供的方便
- Android基础控件之SeekBar(拖动条)
- Android UI控件详解-EditText(编辑框)
- Android UI控件详解-AutoComplete-TextView(自动提示)
- Android UI控件之Gallery(拖动效果) --拖动式图片浏览
- ANDROID L——Material Design详解(UI控件)
- Android UI控件之Gallery(拖动效果) --拖动式图片浏览
- Android UI基础——SeekBar&RatingBar控件
- Android UI详解之SeekBar、ProgressBar和RatingBar
- Android UI控件之Gallery --拖动、覆盖、循环、3D图片浏览 效果之二
- Android UI控件详解-Dialog(对话框合集)
- Android UI控件详解-Notification(通知)
- Android UI控件之Gallery --拖动、覆盖、循环、3D图片浏览 效果之二