【问题标题】:Fix an item in a ObservableScrollView Android修复 ObservableScrollView Android 中的项目
【发布时间】:2014-09-20 14:53:42
【问题描述】:

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

我的 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 是一个包含棕色布局的布局。

有办法修复滚动视图中的项目吗?

【问题讨论】:

    标签: android scrollview material-design googleio


    【解决方案1】:

    使用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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      相关资源
      最近更新 更多