Giter Club home page Giter Club logo

recyclerview-gallery's Introduction

README

Download License Build

中文版文档

This library shows you a gallery using RecyclerView.

小清新的Gallery水平滑动效果

小清新的Gallery垂直滑动效果

Usage

First step, add dependence in your build.gradle.

compile 'com.ryan.rv_gallery:rv-gallery:1.1.2'

Second step, using GalleryRecyclerView in your layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:fitsSystemWindows="true"
    android:gravity="center"
    android:orientation="vertical">

	<!-- PagerSnapHelper can move just one page when scroll -->
	<!-- LinearSnapHelper can move serveral page when scroll-->
    <com.ryan.rv_gallery.GalleryRecyclerView
        android:id="@+id/rv_list"
        android:layout_width="match_parent"
        android:layout_height="480dp"
    	app:helper="PagerSnapHelper/LinearSnapHelper" />

</RelativeLayout>

Third step, init your GalleryRecyclerView in your java code just like using the normal RecyclerView. Note that you must use the LinearLayoutManager as your LayoutManager. At the same time, you must set the orientation like HORIZONTAL or VERTICAL, to make your GalleryRecyclerView scroll horizontally or vertically.

GalleryRecyclerView mRecyclerView = findViewById(R.id.rv_list);
RecyclerAdapter adapter = new RecyclerAdapter(getApplicationContext(), getDatas());
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
mRecyclerView.setAdapter(adapter);

Finally, set some params of GalleryRecyclerView if your need, and you must use the setUp() method to make the GalleryRecyclerView to work.

mRecyclerView
        // set scroll speed(pixel/s)
        .initFlingSpeed(9000)
		// set page distance and visible distance of the nearby.
        .initPageParams(0, 40)
        // set the animation factor
        .setAnimFactor(0.1f)
		// set animation type. you can choose AnimManager.ANIM_BOTTOM_TO_TOP or AnimManager.ANIM_TOP_TO_BOTTOM
        .setAnimType(AnimManager.ANIM_BOTTOM_TO_TOP)
        // set click listener
        .setOnItemClickListener(this)
        // set whether auto play
        .autoPlay(false)
        // set auto play intervel 
        .intervalTime(2000)
        // set default position
        .initPosition(1)
        // finally call method
        .setUp();

You also can release GalleryRecyclerView if you need

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mRecyclerView != null) {
        // release
        mRecyclerView.release();
    }
}

API

Java API

  1. initFlingSpeed(int speed):set scroll speed(pixel/s)
  2. setAnimFactor(float factor):set the animation factor
  3. setAnimType(int type):set animation type. you can choose AnimManager.ANIM_BOTTOM_TO_TOP or AnimManager.ANIM_TOP_TO_BOTTOM
  4. setOnItemClickListener(OnItemClickListener mListener):set click listener
  5. initPageParams(int pageMargin, int leftPageVisibleWidth):set page distance and visible distance of the nearby.
  6. getScrolledPosition(): get current position
  7. getLinearLayoutManager():get LayoutManager
  8. getOrientation():get current scroll orientation(HORIZONTAL:0 VERTICAL:1)
  9. autoPlay(boolean):set can it auto play
  10. intervalTime(int interval):set auto play intervel
  11. initPosition(int position): set default position

XML API

  1. app:helper="PagerSnapHelper/LinearSnapHelper":PagerSnapHelper can move just one page when scroll,LinearSnapHelper can move serveral page when scroll.

Version feature

see more in Releases

License

Copyright 2017 ryanlijianchang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

recyclerview-gallery's People

Contributors

ryanlijianchang avatar jefshi 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.