最大值SeekBar为100然后如何将Seekbar默认值设置为50(从50%开始).搜索栏将从50开始.
我有一个示例代码,但它会从0到100开始.如果您有任何想法,请回答我...谢谢.
public class MainActivity extends Activity implements OnSeekBarChangeListener{
private SeekBar bar; // declare seekbar object variable
// declare text label objects
private TextView textProgress,textAction;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// load the layout
setContentView(R.layout.activity_main);
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
// since we are using this class as the listener the class is "this"
// make text label for progress value
textProgress = (TextView)findViewById(R.id.textViewProgress);
// make text label for action
textAction = (TextView)findViewById(R.id.textViewAction);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// change progress text label with current seekbar value
textProgress.setText("The value is: "+progress);
// change action text label to changing
textAction.setText("changing");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
textAction.setText("starting to track touch");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
textAction.setText("ended tracking touch");
}
}
Run Code Online (Sandbox Code Playgroud)
Muh*_*aat 20
在XML中:
android:progress="50" // or any other value
Run Code Online (Sandbox Code Playgroud)
在Java中:
mSeekbar.setProgress(50); // or any other value
Run Code Online (Sandbox Code Playgroud)
如果你不知道什么是最大值,只想让它达到50%:
mSeekbar.setProgress(mSeekbar.getMax()/2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24491 次 |
| 最近记录: |