0

我正在尝试修复 ScrollView 中的一个项目,当它击中 ActionBar 时。它正确停止,但是当我返回主滚动位置时,我在布局上方得到一个随机边距(屏幕截图 3)。(截图 2 中的边距不是错误)

问题截图

我的 ObservableScrollView 监听器

if(t > stackHeight && !animationActionBarstackedBg){
                animationActionBarstackedBg = true;
            } else if (t < stackHeight && animationActionBarstackedBg){
                animationActionBarstackedBg = false;
            }

            frameImg.setPadding(frameImg.getPaddingLeft(), t/2, frameImg.getPaddingRight(), frameImg.getPaddingBottom());

            if(animationActionBarstackedBg){
                panelTitleContainer.setPadding(panelTitleContainer.getPaddingLeft(), t-stackHeight, panelTitleContainer.getPaddingRight(), panelTitleContainer.getPaddingBottom());
            }

其中 t 是 ScrollY,stackHeight 是图像高度,frameImg 是一个 FrameLayout,其中包含一个 ImageView(用于制作类似 Google I/O 2014 的动画),而 panelTitleContainer 是一个包含棕色布局的布局。

有一种方法可以修复滚动视图中的项目吗?

4

1 回答 1

0

通过使用解决setTranslationY()

if(t > stackHeight && !animationActionBarstackedBg){
    animationActionBarstackedBg = true;
} else if (t < stackHeight && animationActionBarstackedBg){
    animationActionBarstackedBg = false;
}

frameImg.setTranslationY(svMain.getScrollY() * 0.5f);

if(!animationActionBarstackedBg){
    panelTitleContainer.setTranslationY(0);
} else {
    panelTitleContainer.setTranslationY(svMain.getScrollY() - stackHeight);
}
于 2014-08-01T07:51:55.330 回答