当前位置: 首页 > 知识库问答 >
问题:

如何创建具有上一页和下一页预览的ViewPager,以及从预览缩放的ViewPaker

潘翊歌
2023-03-14
viewPager.setClipToPadding(false);
viewPagerMusicCategory.setPadding(width/3, 0, width /3, 0);
viewPagerMusicCategory.setPageMargin(40));

提前谢谢

共有2个答案

萧越泽
2023-03-14

在<code>recyclerview</code>中使用它,然后使用snap helper

public class CenterZoomLayoutManager extends LinearLayoutManager {

    private final float mShrinkAmount = 0.15f;
    private final float mShrinkDistance = 0.9f;

    public CenterZoomLayoutManager(Context context) {
        super(context);
    }

    public CenterZoomLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }


    @Override
    public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
        int orientation = getOrientation();
        if (orientation == VERTICAL) {
            int scrolled = super.scrollVerticallyBy(dy, recycler, state);
            float midpoint = getHeight() / 2.f;
            float d0 = 0.f;
            float d1 = mShrinkDistance * midpoint;
            float s0 = 1.f;
            float s1 = 1.f - mShrinkAmount;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                float childMidpoint =
                        (getDecoratedBottom(child) + getDecoratedTop(child)) / 2.f;
                float d = Math.min(d1, Math.abs(midpoint - childMidpoint));
                float scale = s0 + (s1 - s0) * (d - d0) / (d1 - d0);
                child.setScaleX(scale);
                child.setScaleY(scale);
            }
            return scrolled;
        } else {
            return 0;
        }
    }

    @Override
    public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
        int orientation = getOrientation();
        if (orientation == HORIZONTAL) {
            int scrolled = super.scrollHorizontallyBy(dx, recycler, state);

            float midpoint = getWidth() / 2.f;
            float d0 = 0.f;
            float d1 = mShrinkDistance * midpoint;
            float s0 = 1.f;
            float s1 = 1.f - mShrinkAmount;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                float childMidpoint =
                        (getDecoratedRight(child) + getDecoratedLeft(child)) / 2.f;
                float d = Math.min(d1, Math.abs(midpoint - childMidpoint));
                float scale = s0 + (s1 - s0) * (d - d0) / (d1 - d0);
                child.setScaleX(scale);
                child.setScaleY(scale);
            }
            return scrolled;
        } else {
            return 0;
        }

    }
}

回收器视图中使用它并使用快速助手

recyclerView.setAdapter(mAdapter);
CenterZoomLayoutManager layoutManager = new CenterZoomLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);

recyclerView.setLayoutManager(layoutManager);
        new LinearSnapHelper().attachToRecyclerView(recyclerView);

recyclerView.setScrollingTouchSlop(  recyclerView.TOUCH_SLOP_PAGING);
莘昊
2023-03-14
viewPagerMusicCategory.setPageTransformer(false, new ViewPager.PageTransformer() {
        @Override
        public void transformPage(View page, float position) {
            Log.e("pos",new Gson().toJson(position));
            if (position < -1) {
                page.setScaleY(0.7f);
                page.setAlpha(1);
            } else if (position <= 1) {
                float scaleFactor = Math.max(0.7f, 1 - Math.abs(position - 0.14285715f));
                page.setScaleX(scaleFactor);
                Log.e("scale",new Gson().toJson(scaleFactor));
                page.setScaleY(scaleFactor);
                page.setAlpha(scaleFactor);
            } else {
                page.setScaleY(0.7f);
                page.setAlpha(1);
            }
        }
    }
);

....

 类似资料:
  • 问题内容: 在http://github.com上,开发人员保留项目的HTML,CSS,JavaScript和图像文件。如何在浏览器中看到HTML输出? 当我打开它时,它不会显示作者代码的呈现HTML。它将页面显示为源代码。 是否可以直接将其视为呈现的HTML?否则,我总是需要下载整个ZIP文件才能查看结果。 问题答案: 在GitHub上预览HTML文件最舒适的方法是转到https://htmlp

  • 在 Dreamweaver 中、浏览器中和移动设备上预览您的网页。 实时预览可让您在浏览器中和移动设备上预览您的页面,并在编码时在浏览器中或设备中实时查看更改。 “实时”视图可让您了解页面在 Web 上的显示效果,并允许您在“代码”视图中编辑项目。 “设计”视图还可让您了解页面在 Web 上的显示效果,但是页面呈现的效果并不会与浏览器中的效果完全相同。 “在浏览器中打开”功能使您能够看到页面在浏览

  • 我想在屏幕中的页面预览之前显示viewpager。前一页和下一页在屏幕中显示深度,并用深度动画滑动下一页。 你可以看看这个图像 我怎么做?

  • Cocos Creator 从 v2.2 开始新增了自定义网页预览功能。 自定义网页预览 在项目文件夹下创建 preview-templates 文件。 结构类似: project-folder |--assets |--build |--preview-templates 开始自定义网页预览,可以参考编辑器内置的 preview-templates 文件。自定义完成后需要 重启编辑

  • 绝大多数浏览器对CSS都有很好的支持,设计师不必担心其设计的CSS不被浏览器所支持。 而在实际开发中,最让设计师头痛的是各个浏览器对新标准的支持程度,以及在CSS细节上的处理差异。经常出现的情况是,在一种浏览器中设计的效果,在另一个浏览器中并没有像预期的那样显示。因此,页面开发完成后,应该在一个或多个平台的几种浏览器下对网站进行充分测试,查看页面是不是按照预期的方式工作。 你并不知道用户使用哪种浏

  • 本文向大家介绍如何做图片预览,如何放大一个图片?相关面试题,主要包含被问及如何做图片预览,如何放大一个图片?时的应答技巧和注意事项,需要的朋友参考一下 https://blog.csdn.net/Bule_daze/article/details/79543690