标签:
1. SeekBarDemo
public class SeekBarDemo extends AppCompatActivity { private SeekBar seekBar = null; private TextView textView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_seek_bar_demo); this.seekBar = (SeekBar)findViewById(R.id.seekbar); //取得seekBar this.textView = (TextView)findViewById(R.id.text); //取得TextView this.textView.setMovementMethod(ScrollingMovementMethod.getInstance()); //滚动文本 this.seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl()); } private class OnSeekBarChangeListenerImpl implements SeekBar.OnSeekBarChangeListener { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { SeekBarDemo.this.textView.append("**开始拖动,当前值"+seekBar.getProgress()+"\n"); } @Override public void onStartTrackingTouch(SeekBar seekBar) { textView.append("**,正在拖动,当前值:"+seekBar.getProgress()+"\n"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { textView.append("**,停止拖动,当前值:"+seekBar.getProgress()+"\n"); } } }
2. activity_seek_bar_demo.xml
<SeekBar android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/seekbar"/> <!--使用垂直滚动条--> <TextView android:id="@+id/text" android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/seekbar" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="45dp" />
由于滚动条的每一次的操作都需要进行监听,为了让之textView的文字过多无法显示,所以在TextView中使用了如下的代码进行滚动条设置。
this.textView.setMovementMethod(ScrollingMovementMethod.getInstance()); //滚动文本
只有加上此操作,
android:scrollbars="vertical"
配置的滚动条才能正常显示
标签:
原文地址:http://my.oschina.net/u/1414017/blog/520592