Giter Site home page Giter Site logo

circularui's Introduction

CircularUI

Display views in circular shape with smooth scroll and item click action.

demo video demo video

How To Use

Step 1. Add the JitPack repository to your gradle file

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

Step 2. Add the dependency

dependencies {
        compile 'com.github.JungHsuan:CircularList:1.2.3'
}

Step 3. Add CircularListView in your layout xml

<com.jh.circularlist.CircularListView
        android:id="@+id/my_circular_list"
        android:layout_width="300dp"
        android:layout_height="300dp"/>

Step 4. Create an custom adaper extend from CircularAdapter

    // you should extends CircularAdapter to add your custom item
    private class CircularItemAdapter extends CircularAdapter {

        private ArrayList<String> mItems;       // custom data, here we simply use string
        private LayoutInflater mInflater;       
        private ArrayList<View> mItemViews;     // to store all list item 

        public CircularItemAdapter(LayoutInflater inflater, ArrayList<String> items){
            this.mItemViews = new ArrayList<>();
            this.mItems = items;
            this.mInflater = inflater;

            for(final String s : mItems){
                View view = mInflater.inflate(R.layout.view_circular_item, null);
                TextView itemView = (TextView) view.findViewById(R.id.bt_item);
                itemView.setText(s);
                mItemViews.add(view);
            }
        }

        @Override
        public ArrayList<View> getAllViews() {
            return mItemViews;
        }

        @Override
        public int getCount() {
            return mItemViews.size();
        }

        @Override
        public View getItemAt(int i) {
            return mItemViews.get(i);
        }

        @Override
        public void removeItemAt(int i) {
            if(mItemViews.size() > 0) {
                // remove from view list
                mItemViews.remove(i);
                // this is necessary to call to notify change
                notifyItemChange(); 
            }
        }

        @Override
        public void addItem(View view) {
            // add to view list
            mItemViews.add(view);
            // // this is necessary to call to notify change
            notifyItemChange();
        }
    }

Step 4. inistialize CircularListView in your activity

// simple text item with numbers 0 ~ 9
ArrayList<String> itemTitles = new ArrayList<>();
for(int i = 0 ; i < 6 ; i ++){
        itemTitles.add(String.valueOf(i));
}

CircularListView circularListView = (CircularListView) findViewById(R.id.my_circular_list);
CircularItemAdapter adapter = new CircularItemAdapter(getLayoutInflater(), itemTitles);
circularListView.setOnItemClickListener(new CircularTouchListener.CircularItemClickListener() {
            @Override
            public void onItemClick(View view, int index) {
            }
        });

Add an item into list

// inflate a layout
View view = getLayoutInflater().inflate(R.layout.view_circular_item, null);
TextView itemView = (TextView) view.findViewById(R.id.bt_item);
itemView.setText(String.valueOf(adapter.getCount() + 1));

// add to list
adapter.addItem(view);

Remove an item from list

adapter.removeItemAt(index);

Set circle radius

Value smaller than zero will be set as zero.

circularListView.setRadius(float r);

circularui's People

Contributors

junghsuan avatar

Watchers

 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.