滑块和进度条范例

xml布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textView01" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ProgressBar android:id="@+id/progressBar01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="20" style="@android:style/Widget.ProgressBar.Horizontal" /> <SeekBar android:id="@+id/seekBar01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="20" /> </LinearLayout>  

 

代码

package lyh.Sample_5_5; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.TextView; public class Sample_5_5 extends Activity { private static final double MAX = 100; private TextView tv; private ProgressBar pb; private SeekBar sb; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView)this.findViewById(R.id.textView01); pb = (ProgressBar)this.findViewById(R.id.progressBar01); sb = (SeekBar)this.findViewById(R.id.seekBar01); sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub pb.setProgress(sb.getProgress()); tv.setText("进度"+sb.getProgress()); } }); } } 

 

运行效果

滑块和进度条范例_第1张图片

你可能感兴趣的:(xml,android,layout,Class,import,encoding)