Rating Bar Widget

Rating Bar is used to rate some topics, items or products. We can assign a number of start to signify how much we like the item. Below is an example of the rating bar.

Step 1: The Project Structure (HelloRatingBar)

Step 2: Layout file (activity_main.xml)

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android

xmlns:tools=”http://schemas.android.com/tools

android:layout_width=”match_parent”

android:layout_height=”match_parent”

android:paddingBottom=”@dimen/activity_vertical_margin”

android:paddingLeft=”@dimen/activity_horizontal_margin”

android:paddingRight=”@dimen/activity_horizontal_margin”

android:paddingTop=”@dimen/activity_vertical_margin”

tools:context=”.MainActivity” >

<RatingBar android:id=”@+id/ratingbar”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:numStars=”5″

android:stepSize=”1.0″/>

</RelativeLayout>

Step 3: The Source Code (MainActivity.java)

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android

xmlns:tools=”http://schemas.android.com/tools

android:layout_width=”match_parent”

android:layout_height=”match_parent”

android:paddingBottom=”@dimen/activity_vertical_margin”

android:paddingLeft=”@dimen/activity_horizontal_margin”

android:paddingRight=”@dimen/activity_horizontal_margin”

android:paddingTop=”@dimen/activity_vertical_margin”

tools:context=”.MainActivity” >

<RatingBar android:id=”@+id/ratingbar”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:numStars=”5″

android:stepSize=”1.0″/>

</RelativeLayout>

Step 4: The Output

Leave a Reply

Your email address will not be published. Required fields are marked *