Git Product home page Git Product logo

gallerylayoutmanager's Introduction

GalleryLayoutManager

中文

A custom LayoutManager to build a Gallery or a ViewPager like RecyclerView that shows items in a center-locked and support both HORIZONTAL and VERTICAL scroll.And View Recycle Machine is also supported.

Screenshots

ViewPager

Demo

Usage

1、Build

Gradle

implementation 'github.hellocsl:GalleryLayoutManager:{latest-release-version}'

2、In your code

Basis Usage

Use GalleryLayoutManager#attach(RecycleView recycleView) to setup GalleryLayoutManager for your RecycleView instead of RecycleView#setLayoutManager(LayoutManager manager)

GalleryLayoutManager layoutManager = new GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL);
//layoutManager.attach(mPagerRecycleView);  // default selected position is 0
layoutManager.attach(mPagerRecycleView, 30);

//...
//setup adapter for your RecycleView
mPagerRecycleView.setAdapter(imageAdapter);

Listen to selection change

layoutManager.setCallbackInFling(true);//should receive callback when flinging, default is false
layoutManager.setOnItemSelectedListener(new GalleryLayoutManager.OnItemSelectedListener() {
    @Override
    public void onItemSelected(RecyclerView recyclerView, View item, int position) {
        //.....
    }
});

Apply ItemTransformer just like ViewPager

Implements your ItemTransformer

public class ScaleTransformer implements GalleryLayoutManager.ItemTransformer {

    @Override
    public void transformItem(GalleryLayoutManager layoutManager, View item, float fraction) {
        item.setPivotX(item.getWidth() / 2.F);
        item.setPivotY(item.getHeight() / 2.F);
        float scale = 1 - 0.3F * Math.abs(fraction);
        item.setScaleX(scale);
        item.setScaleY(scale);
    }
}
// Apply ItemTransformer just like ViewPager
layoutManager.setItemTransformer(new ScaleTransformer());

License

Copyright [2017] [Hello Csl]

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.

gallerylayoutmanager's People

Contributors

bcsl avatar liushuai42 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gallerylayoutmanager's Issues

Is fling velocity configurable?

Thanks for this great library!

Except one thing - The fling velocity is too high; I mean, even for a moderate fling, pages skip a lot.

Of course this is quite subjective, but is there a way to configure the fling friction?

使用GalleryLayoutManager之后item显示不出来

这是我的代码
List lisr = new ArrayList<>();
for (int i = 0; i <20 ; i++) {
lisr.add("item"+i);
}
adapter = new NoticeBannerAdapter(lisr);
new GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL).attach(recycleBanner);
recycleBanner.setAdapter(adapter);

下面是打印出来的日志

D/GalleryLayoutManager: onLayoutChildren() called with: state = [State{mTargetPosition=-1, mData=null, mItemCount=20, mIsMeasuring=false, mPreviousLayoutItemCount=0, mDeletedInvisibleItemCountSincePreviousLayout=0, mStructureChanged=true, mInPreLayout=false, mRunSimpleAnimations=false, mRunPredictiveAnimations=false}]
reset:
D/GalleryLayoutManager: firstFillCover finish:first: 0,last:0
V/GalleryLayoutManager: onScrolled: dx:0,dy:0
onScrolled: dx:0,dy:0
D/GalleryLayoutManager: onLayoutChildren() called with: state = [State{mTargetPosition=-1, mData=null, mItemCount=20, mIsMeasuring=false, mPreviousLayoutItemCount=20, mDeletedInvisibleItemCountSincePreviousLayout=0, mStructureChanged=false, mInPreLayout=false, mRunSimpleAnimations=false, mRunPredictiveAnimations=false}]
onLayoutChildren: ignore extra layout step
D/OpenGLRenderer: endAllActiveAnimators on 0x7f7c70c000 (RippleDrawable) with handle 0x7f7decc840

请问下我是不是哪里写的有点问题,我把这些代码复制到一个新开的项目,能显示,然后在自己项目中引用就显示不出来,我看打印出来的日志mItemCount是有20条的。

scrollToPosition not working

hi, scrollToPosition method not working for call galleryLayoutManager.scrollToPosition(position). It only works with galleryLayoutManager.attach(recyclerView, position) method.

点击删除条目bug

我加了点击删除条目的功能,
在定位到position=1的条目后点击删除这个条目(调用notifyitemremoved), 然后position为0的条目也会跟着不见了,定位到其他position上没这个问题

有个问题请教一下

实际运用中有个问题,我现在用的是
GalleryLayoutManager.HORIZONTAL
galleryLayoutManager.setItemTransformer(new ScaleTransformer());
GalleryAdapter galleryAdapter = new GalleryAdapter(thumbs);
thumbs10张
但是刚进页面时,大概有7,8次滑动bug,只要滑到第4张就自动跳到第1张。 这个情况bug,能持续7,8个回合,然后滑动到最后一张就又正常了。

Not working with Kotlin code

I am trying to implement GallaryLayoutManager in my kotlin code like below. but unfortunately it is not working with kotlin code.

val layoutManager = GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL)
        layoutManager.attach(recyclerView, 0)
        layoutManager.setCallbackInFling(true) //should receive callback when flinging, default is false
        layoutManager.setOnItemSelectedListener { recyclerView, item, position ->
            println("===position=== $position")
        }
        layoutManager.setItemTransformer(ScaleTransformer())

If anyone have idea please let me know how to fix it.

LoadMore RecyclerView

Is this support load more feature ?
I am trying to use this library in one of my project where i need this type of LayoutManager but with one more functionality that is loadmore.

How will i achieve this functionality please guide me
Thanks

与GreenDao冲突

More than one file was found with OS independent path 'lib/armeabi-v7a/libRS

出现左右摆动异常

在setOnItemSelectedListener中调用 recyclerView.getAdapter().notifyDataSetChanged(); 手指在屏幕生来回滑动后,可能出现自动左右滑动现象

无法使用scrollToPosition会有大问题

smoothScrollToPosition可以使用,scrollToPosition无法使用,导致切换视图时无法定位到指定position,切换完成后出现一个平滑滚动的动画效果

Expand/collapse child views

Hi BCsl, I want to add the ability to expand/collapse my recyclerview items using the GalleryLayoutManager.
I went through the source code to find out why it doesn't work, but I cannot seem to find it.
It works using a regular LinearLayoutManager but not using the GalleryLayoutManager.

It seems the items are not redrawn when I expand my child view.
Whenever I scroll the view out of bounds and forces the view to redraw, I can see that the view got updated, but I cannot see the animation and expanding happening at realtime.

Hope you can help me out and guide me in the right direction

scrollToPosition(int position) not working

Thank you for nice library! Would you like to add implementation of scrollToPosition(int position)? It will be great as there is need to start show gallery from specified position.

滑动太快出现IndexOutOfBoundsException

android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(Unknown Source:614)

2 android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(Unknown Source:5)
3 android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(Unknown Source:1)
4 github.hellocsl.layoutmanager.gallery.GalleryLayoutManager.d(Unknown Source:161)
5 github.hellocsl.layoutmanager.gallery.GalleryLayoutManager.b(Unknown Source:11)
6 github.hellocsl.layoutmanager.gallery.GalleryLayoutManager.scrollHorizontallyBy(Unknown Source:142)
7 android.support.v7.widget.RecyclerView.scrollStep(Unknown Source:25)
8 android.support.v7.widget.RecyclerView$ViewFlinger.run(Unknown Source:91)
9 android.view.Choreographer$CallbackRecord.run(Choreographer.java:981)
10 android.view.Choreographer.doCallbacks(Choreographer.java:790)

11 android.view.Choreographer.doFrame(Choreographer.java:718)
12 android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
13 android.os.Handler.handleCallback(Handler.java:808)
14 android.os.Handler.dispatchMessage(Handler.java:101)
15 android.os.Looper.loop(Looper.java:166)
16 android.app.ActivityThread.main(ActivityThread.java:7425)
17 java.lang.reflect.Method.invoke(Native Method)
18 com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
19 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

在viewpager里面滑动冲突

我的页面是在viewpager里面的,现在水平滑动事件冲突,我自定义了一个recyclerview来重写了onTouch事件来解决事件冲突的,用普通的水平LinearLayoutManager完全正常,滑动recyclerview到顶部或者底部的时候才滑动viewpager,事件不会冲突,但是用这个GalleryLayoutManager就会事件冲突,滑动就是滑动viewpager,不知道哪里出问题了?可以给个修改方向吗?

RecyclerView in MaterialDialogs library

I tried use your library in Activity and it works fine. But when I try use your library with afollestad MaterialDialogs library, all I have is empty dialog. There's a source:
` MaterialDialog.Builder builder = new MaterialDialog.Builder(this);
builder.title("Выберите год");
View customView = LayoutInflater.from(this).inflate(R.layout.picker_view, null);
RecyclerView recyclerView = (RecyclerView) customView.findViewById(com.allgoritm.youla.R.id.years);

    GalleryLayoutManager manager = new GalleryLayoutManager(GalleryLayoutManager.VERTICAL);
    manager.setCallbackInFling(true);
    manager.setOnItemSelectedListener((recyclerView1, item, position) -> {
        Log.d(TestActivity.class.getSimpleName(), "AHAHAHAHA");
    });
    manager.attach(recyclerView, 40);
    mAdapter = new PickerAdapter(getYears());
    mAdapter.setCallback(this);
    recyclerView.setAdapter(mAdapter);

    builder.customView(customView, true);
    builder.positiveText("Ок");
    builder.onPositive(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            Log.d(TestActivity.class.getSimpleName(), "cool");
        }
    });

    builder.show();`

Is your library supports working with dialogs?

你好,onItemSelected方法返回的position有时候是错误的

你好,我是用了GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL)在我的代码中,并且添加了setOnItemSelectedListener监听,但是在onItemSelected的回调中,position会错乱,总共有四个item,从刚进入展示第一个到逐个滑动到最后一个,position的变化是0-1-0-1-2-2-3-3,在滑动到最后一个item之前,有时会错乱,全部加载之后再滑动才正常

间距

中间放大间距和旁边的不一致,怎么设置间距一致

Select Position in RecyclerView

As far as I can tell you can not programmatically select a position in the recycler view. I tried smoothscroll, scrollby, scrollto, etc and there is no effect.

Is there any way to select a position in the recyclerview and have it scroll to that position?

Reduce velocity in horizontal pager

Love your project!
I'm currently looking for a way to reduce the scroll amount / velocity to switch to the next item in horizontal pager mode.
Fling works very well but moving manually to the next item needs a scroll of more than 50%.
Reducing this to 10% for my usecase is perfect!

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.