android - 使用自定义 ScrollingViewBehavior 跳过 Viewpager 底部填充
问题描述
我有一个选项卡式活动和一个带有自定义 ScrollingViewBehavior 的视图分页器,用于滚动 appbar。滚动应用栏时,视图寻呼机的底部填充跳过。行为(根据另一篇文章的解决方案......)如下:
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
if (appBarLayout == null) {
appBarLayout = (AppBarLayout) dependency;
maxTop = 72;
}
final boolean result = super.onDependentViewChanged(parent, child, dependency);
int currenttop = dependency.getTop();
if (currenttop > maxTop) maxTop = currenttop;
final int bottomPadding = calculateBottomPadding(appBarLayout);
final boolean paddingChanged = bottomPadding != child.getPaddingBottom();
if (paddingChanged) {
child.setPadding(
child.getPaddingLeft(),
child.getPaddingTop(),
child.getPaddingRight(),
bottomPadding);
child.requestLayout();
}
return paddingChanged || result;
}
// Calculate the padding needed to keep the bottom of the view pager's content at the same location on the screen.
private int calculateBottomPadding(AppBarLayout dependency) {
final int totalScrollRange = dependency.getTotalScrollRange();//getTotalScrollRange();
final int deptop = dependency.getTop();
return deptop + totalScrollRange - maxTop;
}
}
结果是(GIF): 滚动行为
为什么要跳过底部?!
对于横向问题:在 onDependentViewChanged 中,我找到了一个用于正确填充的常量值(maxTop=72)!为什么?!我无法理解!
“SOF”和用户的坦克。
解决方案
推荐阅读
- ethereum - 找不到模块“lodash/isString”
- python-3.x - DRF request is not defined for getting current user id
- ajax - 成功参数后获取Ajax变量
- android - How to insert Long Type value to SQLite
- freepascal - 每当我打印列表时它都会跳过第一个输出,我该如何纠正这个问题?
- excel - 在 1 个工作表中合并 2 个事件更改
- sql - 为什么 CONTAINS 和 LIKE 在 SQL 中不起作用?
- php - 在 PHP 中生成 Excel 文件后跳转到另一个页面
- vb.net - 我是 VB (Visual Studio) 的新手,我正在尝试从数据表“ClientInfo”中按升序获取列 (2)“LastName”
- javascript - 数组中的字符串行为异常 - Expo App