android-collapsingtoolbarlayout - 限制嵌套滚动视图在不需要滚动内容时停止滚动
问题描述
我想要做的是......如果内容不需要滚动,我想限制折叠工具栏(图像视图)和 NestedScrollView 的滚动行为及其子相对布局(绿色之一)。Collapsing Tool bar layout 在没有内容可滚动时已成功停止滚动。但是当nestedScrollView 滚动时,即使内容太小而无法滚动并且nestedScrollView 导致滚动appbarLayout。
那么,如果没有像这张图片那样滚动的内容,我怎么能停止滚动嵌套滚动视图呢?
这是我尝试过的。
private void adjustContentSize(double contentHeight) {
int totalScreenHeight = getScreenHeight(this, 1);
showLog("initial Content height -> " + contentHeight / totalScreenHeight);
if (contentHeight > (totalScreenHeight * 0.35) && contentHeight < (totalScreenHeight * 0.45)) {
double contentHeightPercentage = round(contentHeight / totalScreenHeight, 4) + 0.0001;
double appBarHeightPercentage = 1 - contentHeightPercentage;
binding.newsContentView.setMinimumHeight((int) (totalScreenHeight * contentHeightPercentage));
binding.newsHeadIv.getLayoutParams().height = (int) (totalScreenHeight * appBarHeightPercentage);
unlockAppBarOpen(binding.articleAppBarLayout, 1);
showLog("-----------------Content Height : " + contentHeightPercentage + " , Appbar Height : " + appBarHeightPercentage);
changeAppbarLayoutDraggableBehavior(binding.articleAppBarLayout, false);
} else {
showLog("---------------------------------UnAdjustable content------------------------------------");
}
}
private void measureContentSize() {
double contentHeight = binding.newsContentView.getMeasuredHeight();
double totalScreenSize = getScreenHeight(this, 1);
double contentPercentage = contentHeight / totalScreenSize;
if (contentPercentage < 0.35) {
binding.newsContentView.getLayoutParams().height = getScreenHeight(this, 0.35);
changeAppbarLayoutDraggableBehavior(binding.articleAppBarLayout, false);
} else if (contentPercentage == 0.35) {
changeAppbarLayoutDraggableBehavior(binding.articleAppBarLayout, false);
} else {
adjustContentSize(contentHeight);
}
}
measureContentSize()
将数据设置为布局后,我 调用了方法。
解决方案
推荐阅读
- android - 方向布局教程不完整
- java - 找不到 int io.realm.internal.OsSharedRealm.nativeGetRealmPrivileges (long) 的实现
- java - jdbc 驱动程序仅在使用内存时有效
- apache-kafka - 如何使用骆驼创建kafka主题分区
- wordpress - 从搜索结果中排除简码 - wordpress
- java - 在同一窗口中加载新资源
- typescript - 动态设置 HttpParams() 主体
- python - Python - 如何用组的模态值填充字符串值
- html - HTML 更改 mime 类型以使用 chrome 扩展程序下载
- node.js - NextJS 在“.next”目录中找不到有效的构建