One, Seekbar drag bar useThe XML properties and methods supported by Seekbar inherited from Progressbar,progressbar are fully applicable to Seekbar. The difference between a drag bar and a progress bar is that the progress bar uses a color fill to indicate how much progress is completed, while the drag bar identifies the value by the slider position and runs the user drag slider to change the values. Therefore, the drag bar is often used to adjust some of the system's values, such as adjusting the volume, the transparency of the image, and so on.
1. Drag the Bar effect
2. Code implementationFunction: Dynamically change the transparency of a picture by dragging the slider
public class Mainactivity extends Actionbaractivity {private ImageView image = null; @Override protected void OnCreate (Bu Ndle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Image = (ImageView) Findviewbyid (r.id.image); SeekBar SeekBar = (SeekBar) Findviewbyid (R.id.seekbar); Seekbar.setonseekbarchangelistener (New Onseekbarchangelistener () { //trigger the method when the drag bar changes public void Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) {//notification, the progress level have change D Image.setimagealpha (progress);//dynamically change the transparency of the picture } public void Onstoptrackingtouch (SeekBar SeekBar) {// Notification that the user have finished a touch gesture } public void Onstarttrackingtouch (SeekBar SeekBar) {//n Otification the user has started a touch gesture } }); }}
Where the interface layout file Main.xml is:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:orientation=" vertical "> <imageview Android:id= "@+id/image" android:layout_width= "fill_parent" android:layout_height= "250DP" android: src= "@drawable/hehe"/> <!--define a drag bar and change its slider appearance- <seekbar android:id= "@+id/seekbar" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:max= "255" //Set the maximum value of the drag bar android:progress= "255" //Set the current default value of the drag bar android:thumb= "@drawable/android"/> </LinearLayout>
Note: Seekbar allows the user to change the slider appearance of the drag bar, specifying a Drawable object implementation through the Android:thumb property.
second, Ratingbar star rating bar use
Both the interstellar scoring bar and the drag bar inherit from the Absseekbar, which allow the user to drag to change the progress. Ratingbar and Seekbar The biggest difference is: Ratingbar through the stars to express. Common XML attributes supported by Ratingbar are as follows: Android:isindicator: Sets whether the star rating bar allows the user to change (true to not allow modification) Android:numstarts: Set the star rating how many stars are there in total Android : Rating: Set the star rating bar default star android:stepsize: Set How many stars you need to change each time
1. Star rating Effect
2. Code implementationFunction: Change the transparency of the picture by star rating
protected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.main); Image = (ImageView) Findviewbyid (r.id.image); Ratingbar Ratingbar = (ratingbar) Findviewbyid (R.id.ratingbar); Ratingbar.setonratingbarchangelistener (New Onratingbarchangelistener () {public void onratingchanged (RatingBar Ratingbar, float rating, boolean fromuser) { image.setimagealpha (int) (rating*255)/5);//dynamically change the transparency of the picture } });
where the Ratingbar definition (main.xml) is:
<ratingbar android:id= "@+id/ratingbar" android:layout_width= "wrap_content" android:layout_ height= "Wrap_content" android:max= "255" android:numstars= "5" android:stepsize= "0.5 " android:progress= "255"/>
Android progress bar (star rating) use Details (ii)