我在 android 中制作了一个 seekbar,其最大值为 12。
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/mapview"
android:layout_alignParentLeft="true"
android:layout_marginBottom="32dp"
android:max="12"
android:progress="0"
android:layout_marginTop="60dp"
android:secondaryProgress="0" />
我必须在我的 xml 设计中将文本设置为 1,2,3,4....12,位于对应于确切间隔的搜索栏下方?如何做到这一点?
最佳答案
首先,您获得对SeekBar
的引用:
SeekBar bar = (SeekBar) findViewById( R.id.seekBar1 );
bar.setOnSeekBarChangedListener( new OnSeek() );
接下来创建一个实现OnSeekBarChangedListener 的私有(private)类:
private class OnSeek implements OnSeekBarChangeListener {
public void onProgressChanged( SeekBar seekBar, int progress,
boolean fromUser ) {
//Here is where you handle the change in the seekbar e.g.
myTextView.setText( "You are at stage: " + progress );
}
public void onStartTrackingTouch( SeekBar seekBar ) {
//No need to do stuff here
}
public void onStopTrackingTouch( SeekBar seekBar ) {
//No need to do stuff here
}
}
关于android - 如何在android中为每个seekbar间隔设置文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8165299/