首页 > 解决方案 > 限制嵌套滚动视图在不需要滚动内容时停止滚动

问题描述

我正在使用这样的文章视图实施一项活动像这样

我想要做的是......如果内容不需要滚动,我想限制折叠工具栏(图像视图)和 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-collapsingtoolbarlayoutandroid-nestedscrollview

解决方案


推荐阅读