android.support.v4.widget.NestedScrollView.getViewTreeObserver()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中android.support.v4.widget.NestedScrollView.getViewTreeObserver()方法的一些代码示例,展示了NestedScrollView.getViewTreeObserver()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NestedScrollView.getViewTreeObserver()方法的具体详情如下:
包路径:android.support.v4.widget.NestedScrollView
类名称:NestedScrollView
方法名:getViewTreeObserver

NestedScrollView.getViewTreeObserver介绍

暂无

代码示例

代码示例来源:origin: iMeiji/Toutiao

scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
  View view1 = scrollView.getChildAt(scrollView.getChildCount() - 1);
  int diff = (view1.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));

代码示例来源:origin: SalmanZach/SmartStickyHeader

private void setupOnScrollListener() {
  mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
      onScroll(-mScrollView.getScrollY());
    }
  });
  //init scroll listener when the view is ready
  SmartHeaderUtility.executeOnGlobalLayout(mScrollView, new Runnable() {
    @Override
    public void run() {
      onScroll(-mScrollView.getScrollY());
    }
  });
}

代码示例来源:origin: nutbutterfly/android-moving-toolbar

private void setup() {
  nestedScrollView.setOnScrollChangeListener(this);
  ViewTreeObserver viewTreeObserver = nestedScrollView.getViewTreeObserver();
  if (viewTreeObserver.isAlive()) {
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
      @Override
      public void onGlobalLayout() {
        // get size
        int toolbarLinearLayoutHeight = toolbarContainer.getHeight();
        int imageHeight = imageView.getHeight();
        // adjust image frame layout height
        ViewGroup.LayoutParams layoutParams = imageContainer.getLayoutParams();
        if (layoutParams.height != imageHeight) {
          layoutParams.height = imageHeight;
          imageContainer.setLayoutParams(layoutParams);
        }
        // adjust top margin of content linear layout
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) contentContainer.getLayoutParams();
        if (marginLayoutParams.topMargin != toolbarLinearLayoutHeight + imageHeight) {
          marginLayoutParams.topMargin = toolbarLinearLayoutHeight + imageHeight;
          contentContainer.setLayoutParams(marginLayoutParams);
        }
        // call onScrollChange to update initial properties.
        onScrollChange(nestedScrollView, 0, 0, 0, 0);
      }
    });
  }
}

代码示例来源:origin: rubensousa/Transitions

@Override
  public void onGlobalLayout() {
    if (nestedScrollView.getHeight() != 0) {
      appbar.setExpanded(true);
      appbar.addOnOffsetChangedListener(ToolbarActivity.this);
      nestedScrollView.getViewTreeObserver()
          .removeOnGlobalLayoutListener(this);
      nestedScrollView.animate().setStartDelay(400).alpha(1f);
      nestedScrollView.setTranslationY(nestedScrollView.getHeight() / 3);
      nestedScrollView.animate().setStartDelay(400).translationY(0)
          .setInterpolator(new AccelerateDecelerateInterpolator());
    }
  }
});

代码示例来源:origin: rubensousa/Transitions

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setupTransitions();
  setContentView(R.layout.activity_toolbar);
  appbar = (AppBarLayout) findViewById(R.id.appbar);
  nestedScrollView = (NestedScrollView) findViewById(R.id.nestedScrollView);
  collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingLayout);
  if (savedInstanceState == null) {
    nestedScrollView.setAlpha(0f);
    nestedScrollView.getViewTreeObserver()
        .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            if (nestedScrollView.getHeight() != 0) {
              appbar.setExpanded(true);
              appbar.addOnOffsetChangedListener(ToolbarActivity.this);
              nestedScrollView.getViewTreeObserver()
                  .removeOnGlobalLayoutListener(this);
              nestedScrollView.animate().setStartDelay(400).alpha(1f);
              nestedScrollView.setTranslationY(nestedScrollView.getHeight() / 3);
              nestedScrollView.animate().setStartDelay(400).translationY(0)
                  .setInterpolator(new AccelerateDecelerateInterpolator());
            }
          }
        });
  }
}

代码示例来源:origin: ywwynm/EverythingDone

ViewTreeObserver observer = mScrollView.getViewTreeObserver();
observer.addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
  @Override

相关文章