限制嵌套滚动视图以在不需要滚动内容时停止滚动

时间:2019-08-28 06:30:44

标签: android-collapsingtoolbarlayout android-nestedscrollview

我正在使用类似like this

的文章视图实现一项活动

我想做的是...如果内容不必是可滚动的,则我想用其子相对布局(绿色)限制Collapsing Tool bar(Image View)和NestedScrollView的滚动行为。 没有滚动内容时,折叠工具栏布局已成功停止滚动。 但是,即使滚动的内容太小而无法滚动,并且嵌套的ScrollView导致滚动appbarLayout时,滚动nestedScrollView即可。

因此,如果没有如该图片所示的要滚动的内容,如何停止nestedScrollView的滚动?

这是我尝试过的。

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()方法。

0 个答案:

没有答案