Android control seekbar progress bar and ratingbar star sharding bar

Source: Internet
Author: User

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?

 

 

 

 

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.