StackLayoutManager icon indicating copy to clipboard operation
StackLayoutManager copied to clipboard

ScrollOrientation.BOTTOM_TO_TOP & Swipe Left & Right

Open uzman opened this issue 3 years ago • 7 comments

Thanks for the great library.

I want to show items in view like ScrollOrientation.BOTTOM_TO_TOP, but user must be swipe left & right. Is it possible?

Thanks...

uzman avatar Apr 21 '22 16:04 uzman

@uzman I am also trying for the same. Did you achieved it?

jarinrocks avatar Sep 01 '22 14:09 jarinrocks

@jarinrocks I used https://github.com/appsfeature/stack-view-pager. There is missing horizontal transformer. I found it in another repo. https://github.com/FuXiangGit/OrientedAutoViewPager

Create a class from HorizontalBaseTransformer then change onTransform method. You can use it with your view pager: viewPager.setPageTransformer(true, new HorizontalStackTransformer(requireActivity(), 4));

public class HorizontalStackTransformer extends HorizontalBaseTransformer {

    private Context context;
    private int spaceBetweenFirAndSecWith = 10;//第一张卡片和第二张卡片宽度差  dp单位
    private int spaceBetweenFirAndSecHeight = 5;//第一张卡片和第二张卡片高度差   dp单位
    private float pageCountAlpha = 3.0f;//显示几个相对多一个(1.0f就是两个,2.0f就是三个,就是数量加一)

    public HorizontalStackTransformer(Context context, int pageCount) {
        this.context = context;
        this.pageCountAlpha = (float) (pageCount - 1);//在这里减掉1外部不用处理
    }

    public HorizontalStackTransformer(Context context, int spaceBetweenFirAndSecWithHeight, int pageCount) {
        this.context = context;
        this.spaceBetweenFirAndSecWith = spaceBetweenFirAndSecWithHeight;
        this.spaceBetweenFirAndSecHeight = spaceBetweenFirAndSecWithHeight * 2;
        this.pageCountAlpha = (float) (pageCount - 1);//在这里减掉1外部不用处理
    }

    public HorizontalStackTransformer(Context context, int spaceBetweenFirAndSecWith, int spaceBetweenFirAndSecHeight, int pageCount) {
        this.context = context;
        this.spaceBetweenFirAndSecWith = spaceBetweenFirAndSecWith;
        this.spaceBetweenFirAndSecHeight = spaceBetweenFirAndSecHeight;
        this.pageCountAlpha = (float) (pageCount - 1);//在这里减掉1外部不用处理
    }

    @Override
    protected void onTransform(View page, float position) {
        if (position <= 0.0f) {

            page.setAlpha(1.0f);
//            Log.e("onTransform", "position <= 0.0f ==>" + position);
            page.setTranslationX(0f);
            //控制停止滑动切换的时候,只有最上面的一张卡片可以点击
            page.setClickable(true);
        } else if (position <= pageCountAlpha) {//以前用的是3.0显示了4个
            float scale = (float) (page.getHeight() - ScreenUtils.dp2px(context, spaceBetweenFirAndSecHeight * position)) / (float) (page.getHeight());
            page.setAlpha(1.0f);
            page.setClickable(false);
            page.setPivotX(page.getWidth() / 2f);
            page.setPivotY(page.getHeight() / 2f);
            page.setScaleX(scale);
            page.setScaleY(scale);
            page.setTranslationY(page.getHeight() * 0.5f * (1 - scale) + ScreenUtils.dp2px(context, spaceBetweenFirAndSecHeight) * position);
        }
    }
}

uzman avatar Sep 07 '22 06:09 uzman

Thanks a lot. I have managed to achieve that in this library itself.

jarinrocks avatar Sep 07 '22 06:09 jarinrocks