Android学习第六天---seekbar
主xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="match_parent" android:layout_height="wrap_content"/> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
java文件中
import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity implements OnSeekBarChangeListener,OnRatingBarChangeListener{ private SeekBar seekBar = null; private RatingBar ratingBar = null; private static final String TAG="info"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seekBar = (SeekBar) findViewById(R.id.seekBar1); ratingBar = (RatingBar) findViewById(R.id.ratingBar1); seekBar.setOnSeekBarChangeListener(this); ratingBar.setOnRatingBarChangeListener(this); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.i(TAG, ""+progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Log.i(TAG, ""+"StartTrackingTouch"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { Log.i(TAG, "StopTrackingTouch"); } @Override public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) { Log.i(TAG, arg1+""); } }