一个简单的自定义的和容易使用的的picker – HorizontalPicker

HorizontalPicker

一个简单的自定义的和容易使用的的picker

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 useSnapHelper

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

set layout manager of your recyclerVew

recyclerView.setLayoutManager(pickerLayoutManager);

To get selected view useonScrollStopListener

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 addclipToPadding=”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" />

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:一个简单的自定义的和容易使用的的picker – HorizontalPicker