您的位置:首页 > 移动开发 > Android开发

Android SeekBar的使用——简单案例

2014-05-13 00:00 423 查看

seekBar.setOnSeekBarChangeListener监听

自动重写3个方法:

onStopTrackingTouch://拖动后

onStartTrackingTouch://拖动前

onProgressChanged://拖动中

1. [代码]layout

01
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
04
android:layout_height
=
"fill_parent"
>
05
<
SeekBar
android:id
=
"@+id/SeekBar01"
android:layout_width
=
"fill_parent"
06
android:layout_height
=
"wrap_content"
android:max
=
"100"
07
android:progress
=
"50"
android:secondaryProgress
=
"100"
></
SeekBar
>
08
<
TextView
android:id
=
"@+id/TextView1"
android:layout_width
=
"fill_parent"
09
android:layout_height
=
"wrap_content"
android:text
=
""
/>
10
<
TextView
android:id
=
"@+id/TextView2"
android:layout_width
=
"fill_parent"
11
android:layout_height
=
"wrap_content"
android:text
=
""
/>
12
</
LinearLayout
>

2. [代码]Test_SeekBar.java

01
package
com.Aina.Android;
02
03
import
android.app.Activity;
04
import
android.os.Bundle;
05
import
android.widget.SeekBar;
06
import
android.widget.TextView;
07
08
public
class
Test_SeekBar
extends
Activity
implements
SeekBar.OnSeekBarChangeListener{
09
/** Called when the activity is first created. */
10
private
SeekBar seekBar;
11
private
TextView textView1,textView2;
12
@Override
13
public
void
onCreate(Bundle savedInstanceState) {
14
super
.onCreate(savedInstanceState);
15
setContentView(R.layout.main);
16
seekBar = (SeekBar)
this
.findViewById(R.id.SeekBar01);
17
textView1 = (TextView)
this
.findViewById(R.id.TextView1);
18
textView2 = (TextView)
this
.findViewById(R.id.TextView2);
19
seekBar.setOnSeekBarChangeListener(
this
);
//添加事件监听
20
}
21
//拖动中
22
@Override
23
public
void
onProgressChanged(SeekBar seekBar,
int
progress,
24
boolean
fromUser) {
25
this
.textView1.setText(
"当前值:"
+progress);
26
27
}
28
//开始拖动
29
@Override
30
public
void
onStartTrackingTouch(SeekBar seekBar) {
31
this
.textView2.setText(
"拖动中..."
);
32
33
}
34
//结束拖动
35
@Override
36
public
void
onStopTrackingTouch(SeekBar seekBar) {
37
this
.textView2.setText(
"拖动完毕"
);
38
39
}
40
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: