Giter Site home page Giter Site logo

wheelview's Introduction

WheelView

WheelView is an Android library that allows drawables to be placed on a rotatable wheel. It behaves like a Circular ListView where items rotate rather than scroll vertically. It isn't limited by the number of items that can fit on the wheel since it will cycle through each adapter position when the wheel is rotated. It can be rotated at any angle and from any position.

The WheelView can be used as a way to select one item from a list. The SelectionAngle determines what position on the wheel is selected. You can also receive a callback for when an item is clicked, and whether it is selected. Have a look at the sample for a working example!

The library is still in its infancy so if there are any bugs or missing features please let me know!

1 2

Note - Frame rate is much better than these poorly converted gifs!

Usage

  1. Add a custom view in xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.lukedeighton.wheelview.WheelView
        android:id="@+id/wheelview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:wheelColor="@color/grey_400"
        app:rotatableWheelDrawable="false"
        app:selectionAngle="90.0"
        app:wheelPosition="bottom"
        app:wheelOffsetY="60dp"
        app:repeatItems="true"
        app:wheelRadius="276dp"
        app:wheelItemCount="14"
        app:wheelPadding="13dp"
        app:wheelItemRadius="43dp"/>
</RelativeLayout>
  1. Set a WheelAdapter similar to how you would set an adapter with a ListView
wheelView.setAdapter(new WheelAdapter() {
    @Override
    public Drawable getDrawable(int position) {
        //return drawable here - the position can be seen in the gifs above
    }

    @Override
    public int getCount() {
        //return the count
    }
});

Listeners

  1. A listener for when the closest item to the SelectionAngle changes.
wheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectListener() {
    @Override
    public void onWheelItemSelected(WheelView parent, int position) {
        //the adapter position that is closest to the selection angle
    }
});
  1. A listener for when an item is clicked.
wheelView.setOnWheelItemClickListener(new WheelView.OnWheelItemClickListener() {
    @Override
    public void onWheelItemClick(WheelView parent, int position, boolean isSelected) {
        //the position in the adapter and whether it is closest to the selection angle
    }
});
  1. A listener for when the wheel's angle is changed.
wheelView.setOnWheelAngleChangeListener(new WheelView.OnWheelAngleChangeListener() {
    @Override
    public void onWheelAngleChange(float angle) {
        //the new angle of the wheel
    }
});

Attributes

The WheelView is highly customisable with many attributes that can be set via xml or programmatically (recommend using xml as programmatically set attributes is half implemented at the moment). Here are the custom attributes that can be declared in xml:

  • wheelDrawable
  • wheelColor
  • emptyItemDrawable
  • emptyItemColor
  • selectionDrawable
  • selectionColor
  • selectionPadding
  • selectionAngle
  • repeatItems
  • wheelRadius
  • wheelItemRadius
  • rotatableWheelDrawable
  • wheelOffsetX
  • wheelOffsetY
  • wheelItemCount
  • wheelItemAngle
  • wheelToItemDistance
  • wheelPosition
  • wheelPadding
  • wheelItemTransformer
  • selectionTransformer

License

Apache License Version 2.0 http://apache.org/licenses/LICENSE-2.0.txt

wheelview's People

Contributors

lukedeighton avatar

Watchers

Lerist avatar  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.