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

x33g5p2x  于2022-01-16 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(130)

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

Button.getViewTreeObserver介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

final Button tv = (Button)findViewById(R.id.saveit);
 ViewTreeObserver vto = tv.getViewTreeObserver();
 vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
   public void onGlobalLayout() {
     ViewGroup.MarginLayoutParams vlp = (MarginLayoutParams) tv.getLayoutParams();
     int btnsize =tv.getMeasuredHeight()+vlp.topMargin;
     sizeit(btnsize);
     ViewTreeObserver obs = tv.getViewTreeObserver();
     obs.removeGlobalOnLayoutListener(this);
   }
 });

代码示例来源:origin: PopFisher/SmartPopupWindow

private void initViewListener() {
  mAnchorBtn.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
      if (mPopupWindow == null || !mPopupWindow.isShowing()) {
        return;
      }
      updatePopupPos();
    }
  });
}

代码示例来源:origin: stackoverflow.com

final Button button1 = (Button) view.findViewById(R.id.button);
 final CollapseAnimator animator = new CollapseAnimator(topLayout);
 final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
     int mHeight = button1.getMeasuredHeight();
     KLog.i("onGlobalLayout() mHeight:" + mHeight);
     animator.setValues(mHeight*2, mHeight);
   }
 };
 button1.getViewTreeObserver().addOnGlobalLayoutListener(listener);
 button1.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
     view.post(new Runnable() {
       @Override
       public void run() {
         button1.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
         animator.collapse();
       }
     });
   }
 });

相关文章

Button类方法