Ratingbar: A star rating bar. As its name suggests, it is generally used for scoring. However, sometimes it can be used as a horizontal slide and as a tool for setting some programs. The following program uses the star rating bar to adjust the image transparency.
Interface layout File
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="320dp" android:contentDescription="@string/hello" android:src="@drawable/lijiang" /> <RatingBar android:id="@+id/rating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="255" android:numStars="5" android:progress="255" android:stepSize="0.5" /></LinearLayout>
Onratingbarchangelistener is used to monitor the change of score bar.
Public class ratingbartest extends activity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); Final imageview image = (imageview) findviewbyid (R. id. image); ratingbar = (ratingbar) findviewbyid (R. id. rating); ratingbar. setonratingbarchangelistener (New onratingbarchangelistener () {// This method is triggered when the slider position of the drag bar changes @ overridepublic void onratingchanged (ratingbar arg0, float rating, Boolean fromuser) {// dynamically change the transparency of the image, 255 of which is the maximum value of the star rating bar, And // five stars represent the maximum value of 255image. setalpha (INT) (rating * 255/5 ));}});}}