walterFeng / GalleryHelper

show a gallery using RecyclerView.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Build Status

GalleryHelper

This is a very simple library for Android that allows you to view image as gallery using RecyclerView

Video

Usage

  1. Add the dependencies to your build.gradle file, GalleryHelper is avaiable in jitPack:

    //in your root project build.gralde file:
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'//dependencies 
    maven { url 'https://jitpack.io' } //repositories
    
    //in your app project build.gralde file:
    implementation 'com.github.walterFeng:GalleryHelper:1.0.2'
  2. Attach to recyclerView after setContentView():

    // init recyclerView:
    val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
    val adapter = setupAdapter(recyclerView)
    
    // support gallery:
    helper = GalleryHelper.from(recyclerView)
        .attach(loopParams = 500, itemSpace = 40, scale = 0.87f, alpha = 0.9f)
    
    // add page changed listener:
    helper?.pagingScrollHelper?.setOnPageChangedListener(object :
        PagingScrollHelper.OnPageChangedListener {
        override fun onPageChange(index: Int) {
            val i = helper?.lopperHelper?.gerCurrentRealPosition() ?: 0
            val position = i % adapter.itemCount
            Log.d("walter", "onPageChange:$index || position=$position")
        }
    })
  3. Set paddingLeft and paddingRight( or LinearLayoutManager.HORIZONTAL: paddingTop and paddingBottom) to your RecyclerView , you need add android:clipToPadding="false" for RecyclerView in your layout XML:

    <android.support.v7.widget.RecyclerView
         android:id="@+id/recyclerView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:clipToPadding="false"
         android:paddingLeft="50dp"
         android:paddingRight="50dp"/>
  4. Other support:

    helper?.pagingScrollHelper?.setOnPageChangedListener(listener)
    helper?.pagingScrollHelper?.setAutoScroll(enable,duration)
    helper?.pagingScrollHelper?.scrollToNextPage(skip)
    //...
    helper?.lopperHelper?.setLoopEnable(loop)
    //...
    helper?.scaleTransformHelper?.setAnimatorParams(scale,alpha)

    PagingScrollHelper, LopperHelper android ScaleTransformHelper can use alone

License

Android Gallery Helper.
https://github.com/walterFeng/GalleryHelper/

Copyright 2019 Walter Feng

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.

About

show a gallery using RecyclerView.


Languages

Language:Kotlin 100.0%