Code Monkey home page Code Monkey logo

ratingbar's Introduction

RatingBar

RatingBar is a custom widget use to display rating in star.

Integration(集成)

Add maven repository to you root build.gradle:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Then add the dependency to you module build.gradle:

dependencies {
    compile 'com.github.whinc:ratingbar:1.1.1'
}

How to use (如何使用)

Create RatingBar in xml layout:

<com.whinc.widget.ratingbar.RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:rb_max_count="5"
    app:rb_count="3"
    app:rb_empty="@drawable/empty"
    app:rb_fill="@drawable/fill"
    app:rb_space="10dp"
    app:rb_click_rating="true"
    app:rb_touch_rating="true"
    />

Create RatingBar in java code:

RatingBar ratingBar2 = new RatingBar(this);
ratingBar2.setMaxCount(7);
ratingBar2.setCount(4);
ratingBar2.setFillDrawableRes(R.drawable.empty);
ratingBar2.setEmptyDrawableRes(R.drawable.fill);
ratingBar2.setSpace(0);
ratingBar2.setTouchRating(true);
ratingBar2.setClickRating(true);
ratingBar2.setOnRatingChangeListener(new RatingBar.OnRatingChangeListener() {
    @Override
    public void onChange(RatingBar view, int preCount, int curCount) {
        Log.i("TAG", String.format("previous count:%d, current count:%d", preCount, curCount));
    }
});

Note:If you don't want display empty star set it's drawable to null instead of transparent drawable.

Customise (自定义)

First, make sure you have add below namespace to the layout root tag.

xmlns:app="http://schemas.android.com/apk/res-auto"

Here is all the attributes you can use to customise RatingBar.(More Attributes will be add later.)

* app:rb_max_count [Integer default:5] --> max rating count
* app:rb_count [Integer default:0] --> rating count
* app:rb_fill [Drawable default:@drawable/fill] --> star drawable tha has rating
* app:rb_empty [Drawable default:@drawable/empty] --> star drawable that has no rating
* app:rb_space [Dimension default:0] --> space between stars
* app:rb_click_rating [Boolean default:true] --> enable/disable rating with click action
* app:rb_touch_rating [Boolean default:true] --> enable/disable rating with touch action

The MIT License (MIT)

Copyright (c) 2015 WuHui

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ratingbar's People

Contributors

whinc avatar

Stargazers

Melo avatar HyoSeon Kim avatar Kenan avatar Mhmd Dsoki avatar İbrahim Halil TOPRAK avatar Jitrapon Tiachunpun avatar ajayprajapati avatar Efra avatar  avatar no avatar 小 v avatar  avatar Diaa Skaik avatar  avatar Ahmed Hashem avatar 向伟 avatar Eric Lu avatar 一束光线 avatar 独行的苏泽 avatar  avatar Cuong Vo avatar  avatar Levi Bostian avatar  avatar Eric Bachhuber avatar Andres Rodriguez Escudero avatar cenler avatar BrightMI avatar  avatar

Watchers

James Cloos avatar Cuong Vo avatar  avatar ajayprajapati avatar  avatar

ratingbar's Issues

Arabic space not working

Hello,
I have used this library but in Arabic first, start space not working. Please check and let me know.
Thanks
Screenshot from 2019-07-08 16-47-17

0 star

Its not possible to put star to 0 selection, only when the activity start.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.