Giter Site home page Giter Site logo

xlhratingbar's Introduction

中文版

XLhRatingBar

A custom Android ratingbar, no fixed style, everything is specified by you.

Background

We often use the rating bar to do some scoring, progress and rating functions. Android.widget.ratingbar can achieve some simple effects. We can useLayer list and Android: progressdrawable. We can also place some pictures and change the style of the pictures when clicking.

If we want to achieve some complex effects, these solutions will be a bit troublesome:

  • half step size
  • The size of each star varies
  • 1、3、5 step size is 0.5, 2、4、6 stop size is 1.
  • Vertical or oblique

They are all so cumbersome, inflexible, and poorly scalable.

Feature

  • Each internal unit control (star) has three states: unchecked, half selected, and all selected.
  • The selection status of the internal unit control is determined by the user in the callback according to the location of the click.
  • Customize the style of each internal cell control. The user can return the control dynamically according to the location and state of the cell control.
  • Total number of custom property or code setting internal unit controls, selected.
  • Listening in the selected state.

Install

dependencies {
	//other dependencies...
	compile 'com.xingliuhua:xlhratingbar_lib:4.0'
}

Usage

SimpleRatingView

The library and the default implementation of a simple style and function, the default total of 5 stars, each time the minimum can be changed by half. It can be used directly in code or XML files.

XLHRatingBar xlhRatingBar = new XLHRatingBar(this);
//add to viewGroup

or xml file:

<com.xingliuhua.xlhratingbar.XLHRatingBar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:numStars="5"
                app:rating="2.5" />

custom style

implements IRatingView

Iratingview is the behavior abstraction of a single internal control. You can return corresponding values according to your own business requirements. Please refer to the default implementation of simpleratingview.

public interface IRatingView {
    /**
     * you can change your item style by state and position. eg:color,text size.
     * @param state STATE_NONE,STATE_HALF,STATE_FULL
     * @param position star index. start from 0
     * @param starNums star item number
     */
    void setCurrentState(int state,int position,int starNums);

    /**
     * return you start item view,you can custom item by positon
     * @param context
     * @param position star index. start from 0
     * @param starNums star item number
     * @return
     */
    ViewGroup getRatingView(Context context,int position,int starNums);

    /**
     * not selected
     */
    public static final int STATE_NONE = 0;
    /**
     * select half
     */
    public static final int STATE_HALF = 1;
    /**
     * selected
     */
    public static final int STATE_FULL = 2;

}

set class name in xml

<com.example.xlhratingbar.XLHRatingBar
		xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        app:numStars="5"
        app:rating="5"
        app:ratingViewClass="com.example.xlhratingbar_lib.SimpleRatingView"
        />

or set class name in code

 LinearLayout llContainer = (LinearLayout) findViewById(R.id.ll_container);
 XLHRatingBar xlhRatingBar = new XLHRatingBar(this);
 xlhRatingBar.setNumStars(3);
 xlhRatingBar.setEnabled(false);//can not change rating by touch
 xlhRatingBar.setRatingViewClassName("com.example.xlhratingbar.MyRatingView4");
 xlhRatingBar.setOnRatingChangeListener(new XLHRatingBar.OnRatingChangeListener() {
     @Override
     public void onChange(float rating, int numStars) {
        Toast.makeText(getApplicationContext(), "rating:" + rating, 0).show();
     }
 });
 llContainer.addView(xlhRatingBar);

Maintainers

@xingliuhua.

Contributing

Feel free to dive in! [Open an issue] or submit PRs.

xlhratingbar's People

Contributors

xingliuhua avatar

Watchers

James Cloos avatar

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.