Android Study Notes 27: Star Rating

Source: Internet
Author: User

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 ));}});}}



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.