如何将Android ViewPager2的高度包装到当前项目的高度? [英] How to wrap height of Android ViewPager2 to height of current item?

查看:70
本文介绍了如何将Android ViewPager2的高度包装到当前项目的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于新的 ViewPager2 类的.

This question is for the new ViewPager2 class.

有一个

There is a similar question for the old ViewPager, but the solution requires extending ViewPager. However, ViewPager2 is final so cannot be extended.

在我的情况下,我有一个包含三个不同片段的ViewPager2.这些碎片中的一个比其他两个碎片高得多,这意味着当您滑动到一个较短的碎片中时,会有很多空白空间.那么如何有效地将ViewPager2包装到当前片段的高度?

In my situation, I have a ViewPager2 that contains three different fragments. One of these fragments is much taller than the other two, which means when you swipe to one of the shorter fragments, there is a lot of empty space. So how do I effectively wrap the ViewPager2 to the height of the current fragment?

推荐答案

对于这种解决方法我一点都不满意,但是它确实解决了我尝试将ViewPager2与不同高度的片段配合使用时出现的渲染问题.显然,它将减慢渲染速度并消耗更多内存.

I'm not at all happy with this workaround, but it does solve the rendering problems I had when trying to use ViewPager2 with fragments of different heights. It will obviously slow down rendering and consume more memory.

myStupidViewPager2.offscreenPageLimit = fragments.size

这篇关于如何将Android ViewPager2的高度包装到当前项目的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆