GithubHelp home page GithubHelp logo

adityagohad / horizontalpicker Goto Github PK

View Code? Open in Web Editor NEW
359.0 9.0 46.0 1003 KB

A simple, customizable and easy to use picker where centre view is scaled up

License: Apache License 2.0

Java 100.00%
android layoutmanager picker scale centre recyclerview horizontalnumberpicker customizable horizontalpicker recycler

horizontalpicker's Introduction

HorizontalPicker

A simple, customizable and easy to use picker where centre view is scaled up

License Apache Android Arsenal

Demo screen 1

QuickStart

Include the Gradle dependency

dependencies {
    compile 'com.github.adityagohad:HorizontalPicker:1.0.1'
}

Don't forget to add following to build.gradle(Project:{your_project_name>})

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

How to use

Your picker will be recyclerView and this lib is just a custom layout manager to initialize the PickerLayoutManager and set the properties

PickerLayoutManager pickerLayoutManager = new PickerLayoutManager(this, PickerLayoutManager.HORIZONTAL, false);
pickerLayoutManager.setChangeAlpha(true);
pickerLayoutManager.setScaleDownBy(0.99f);
pickerLayoutManager.setScaleDownDistance(0.8f);

To make it snap to centre use SnapHelper

SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);

set layout manager of your recyclerVew

recyclerView.setLayoutManager(pickerLayoutManager);

To get selected view use onScrollStopListener

pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
    @Override
        public void selectedView(View view) {
            //Do your thing
        }
    });
}

Don't forget this

To its core it is a recycler view with custom layout manager so if you forget to add clipToPadding="false" you will never be able to select first and last few elemets(values/views).
So always add paddingLeft and paddingRight like shown below.

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:clipToPadding="false"
        android:paddingLeft="183dp"
        android:paddingRight="183dp" />

horizontalpicker's People

Contributors

4brunu avatar adityagohad avatar amuyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

horizontalpicker's Issues

Set initial selected item or view

I don't see a way to set the initial selected view or item. RecyclerView.smoothScrollToPosition() doesn't seem to scroll to the correct position. Any ideas?

How Can I manage the setOnScrollChangeListener(new PickerLayoutManger.onScrollStopListner())

Hey, Anybody having problem with using
setOnScrollChangeListener(new PickerLayoutManger.onScrollStopListner());

In my project I am trying to include this library but I am unable to use the function above because my my project's minimum level is 19 and the function requires above 23.

I am googling for the way around but have not been fortunate. Is there anyone who had the same issue?

Vertically scrolling is not working

Tried using vertical scroll option by using top and bottom for scaling and height to calculate mid points. My adapter items are not rendered properly. I ensured to change the adapter orientation to vertical also.

vertical functionality

I want the same functionality in vertical view. is it possible ? with the existing code

How to change number visible offset elements

Sorry, there is no direct provision for it although there is method inside PickerLayoutManager called setScaleDownDistance(float value). You can play with the value(at 0.99f you will observe maximum possible elements on screen and as you reduce the value you will see less elements on screen).

Another method is
for sample app I have added margin to the item(view) that goes inside recycler view like this

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/picker_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="32dp"
    android:layout_margin="13dp"/>

you can reduce margin to get more elements on the screen.

Not able to add gradle dependency

when i added the dependency in built.gradle(app) then following error is shown :

Error:(27, 13) Failed to resolve: com.github.adityagohad:HorizontalPicker:1.0.0

The first image does not scale

I use the HorizontalPicker for a list of images. The first and second image does not scale in the first showing. It only scales after I scroll forward and then backward.
Thanks a lot for your help ๐Ÿ‘

scaledownby, scaledowndistance not work at the start app.

Item is imageview.
I make drawable xml file like round shape, and setImageresource xml file.
When i was start app, No scaleDown, No scaleDownDistance, looks like 0dp margin.
I touch recyclerview, suddenly work scaleDown, scaleDownDistance.
Why does this happen?

How to set initial selected item to first item and final item to last item in the list?

I Have a List which contains the number of quantity available for the selected product. I found your library and it was really awesome. So I have implemented and it is working fine as you shown in the gif. but what I can't scroll to the item at the first position to the item at the last position. I have tested with a List containing 1 to 25. I can scroll only from 11 to 17. Please help me with that.

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.