Android Learning-Interface-ui-ratingbar

Source: Internet
Author: User

Activity_main.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/linearlayout1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical"android:padding= "10DP" >    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Change Picture transparency"android:textappearance= "? Android:attr/textappearancelarge" />    <!--Android:numstars How many stars android:rating default how many stars Android:stepsize minimum change 0.5 stars -    <RatingbarAndroid:id= "@+id/ratingbar1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:numstars= "4"android:rating= "4"android:stepsize= "0.5"         />    <ImageViewAndroid:id= "@+id/imageview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/pic1" /></LinearLayout>
View Code

Mainactivity.java

 Public classMainactivityextendsactivity{Ratingbar ratingBar1;        ImageView ImageView1; Handler Handler=NewHandler () { Public voidhandlemessage (Message msg) {if(msg.what==123){                floatAlpha =msg.getdata (). GetFloat ("Alpha"); Imageview1.setimagealpha ((int) Alpha);    }        }    }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); ImageView1=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1); RatingBar1=(Ratingbar) Findviewbyid (R.ID.RATINGBAR1); Ratingbar1.setonratingbarchangelistener (NewOnratingbarchangelistener () {@Override Public voidOnratingchanged (Ratingbar Ratingbar,floatrating,BooleanFromuser) {Message msg=NewMessage (); Msg.what=123; Bundle Data=NewBundle (); //Rating: It's a few stars now .//Getnumstars: How many stars in total//Rating*255/ratingbar1.getnumstars (): Position in 255Data.putfloat ("Alpha", rating*255/ratingbar1.getnumstars ());                Msg.setdata (data);                            Handler.sendmessage (msg);            }        }); }}
View Code

Android Learning-Interface-ui-ratingbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.