Android controls seekbar and ratingbar
1. seekbar is a progress bar. You can drag it to change it;
After dragging:
The original code is as follows:
Layout file:
<?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" ><SeekBar android:id="@+id/seekbarld" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
Java code:
Package Lili. seekbar; import android. app. activity; import android. OS. bundle; import android. widget. seekbar; importandroid. widget. seekbar. onseekbarchangelistener; public class seekbaractivity extendsactivity {/** called when the activity is first created. */privateseekbar seekbar = NULL; @ override publicvoid oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // bind the control seekbar = (seekbar) findviewbyid (R. id. seekbarld); // sets the maximum seekbar of the progress bar. setmax (100); // Add the listener seekbar. setonseekbarchangelistener (newseekbarlistener ();} // a listener that listens for changes in the progress bar status PrivateClass seekbarlistener implements onseekbarchangelistener {// when the progress bar changes, the publicvoid onprogresschanged (seekbar, int progress, booleanfromuser) {system. out. println (Progress);} publicvoid onstarttrackingtouch (seekbar) {system. out. println ("START->" + seekbar. getprogress ();} publicvoid onstoptrackingtouch (seekbar) {system. out. println ("stop->" + seekbar. getprogress ());}}}
2. ratingbar is a split bar, which is represented by stars.
Click the stars:
Original code:
Layout file:
<?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" ><RatingBar android:id="@+id/ratingbarld" android:layout_height="wrap_content" android:layout_width="wrap_content" android:numStars="5" android:stepSize="13.0" /></LinearLayout>
Java file:
package lili.ratingbar; import android.app.Activity;import android.os.Bundle;import android.widget.RatingBar; public class RatingBarActivity extends Activity{ /**Called when the activity is first created. */ privateRatingBar ratingBar=null; @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ratingBar=(RatingBar)findViewById(R.id.ratingbarld); ratingBar.setOnRatingBarChangeListener(newRatingBarListener()); } private class RatingBarListener implementsRatingBar.OnRatingBarChangeListener{ @Override publicvoid onRatingChanged(RatingBar ratingBar, float rating, booleanfromUser) { System.out.println("rating-->"+rating); } }}
However, we generally want to improve the ratingbar decoration and use better-looking images to replace the default images of the system. How should we change it?