当前位置: 首页>>代码示例>>Java>>正文


Java ViewTreeObserver类代码示例

本文整理汇总了Java中android.view.ViewTreeObserver的典型用法代码示例。如果您正苦于以下问题:Java ViewTreeObserver类的具体用法?Java ViewTreeObserver怎么用?Java ViewTreeObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ViewTreeObserver类属于android.view包,在下文中一共展示了ViewTreeObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Initialize

import android.view.ViewTreeObserver; //导入依赖的package包/类
public void Initialize() {
    _imageView = ((AppCompatActivity) _context).findViewById(R.id.skeletonList_backdrop_image_main);
    ViewTreeObserver imageViewViewTreeObserver = _imageView.getViewTreeObserver();
    imageViewViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            Logger.getInstance().Debug(TAG, "_imageView imageViewViewTreeObserver onGlobalLayout");
            calculateReferenceSize();
            _imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });

    _relativeLayoutMapPaint = ((AppCompatActivity) _context).findViewById(R.id.skeletonList_backdrop_relativeLayoutPaint_main);
    ViewTreeObserver relativeLayoutViewTreeObserver = _relativeLayoutMapPaint.getViewTreeObserver();
    relativeLayoutViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            Logger.getInstance().Debug(TAG, "_relativeLayoutMapPaint relativeLayoutViewTreeObserver onGlobalLayout");
            calculateReferenceSize();
            _relativeLayoutMapPaint.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:26,代码来源:MapContentViewBuilder.java

示例2: onActivityReenter

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }

    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);

}
 
开发者ID:googlesamples,项目名称:android-instant-apps,代码行数:34,代码来源:MainActivity.java

示例3: onPreDraw

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override public boolean onPreDraw() {
  ImageView target = this.target.get();
  if (target == null) {
    return true;
  }

  ViewTreeObserver vto = target.getViewTreeObserver();
  if (!vto.isAlive()) {
    return true;
  }

  int width = target.getWidth();
  int height = target.getHeight();

  if (width <= 0 || height <= 0 || target.isLayoutRequested()) {
    return true;
  }

  target.removeOnAttachStateChangeListener(this);
  vto.removeOnPreDrawListener(this);
  this.target.clear();

  this.creator.unfit().resize(width, height).into(target, callback);
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:DeferredRequestCreator.java

示例4: onCreate

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getComponent().inject(this);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_signin);
    binding.setViewmodel(viewModel);
    binding.container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            binding.bottomBar.post(new Runnable() {
                @Override
                public void run() {
                    binding.bottomBar.setVisibility(binding.container.getRootView().getHeight() - binding.container.getHeight() > dpToPx(SignInActivity.this, 200) ? View.GONE : View.VISIBLE);
                }
            });
        }
    });
}
 
开发者ID:tresorit,项目名称:ZeroKit-Android-Sample,代码行数:19,代码来源:SignInActivity.java

示例5: doOnViewCreated

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override
public void doOnViewCreated(View v, @Nullable Bundle savedInstanceState) {
    statusCircle = v.findViewById(R.id.statusCircle);
    statusHint = (OneSheeldTextView) v.findViewById(R.id.statusHint);
    rmsIndicator = (TextView) v.findViewById(R.id.rmsLevelIndicator);
    recognizedResult = (OneSheeldTextView) v
            .findViewById(R.id.recognizedResult);
    params = (LayoutParams) rmsIndicator.getLayoutParams();
    statusCircle.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (stepValue == 0)
                        stepValue = statusCircle.getHeight() / 10;
                }
            });
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:19,代码来源:SpeechRecognitionFragment.java

示例6: setImageBitmap

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override
public void setImageBitmap(Bitmap bm) {
    // TODO Auto-generated method stub
    super.setImageBitmap(bm);
    //大小为0 表示当前控件大小未测量  设置监听函数  在绘制前赋值
    if(getWidth()==0){
        ViewTreeObserver vto = getViewTreeObserver();
        vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
        {
            public boolean onPreDraw()
            {
                initData();
                //赋值结束后,移除该监听函数
                MatrixImageView.this.getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    }else {
        initData();
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:22,代码来源:MatrixImageView.java

示例7: initializeDrawListener

import android.view.ViewTreeObserver; //导入依赖的package包/类
public static void initializeDrawListener(View view) {
    if (sGlobalDrawListener != null) {
        view.getViewTreeObserver().removeOnDrawListener(sGlobalDrawListener);
    }
    sGlobalDrawListener = new ViewTreeObserver.OnDrawListener() {
            private long mTime = System.currentTimeMillis();
            public void onDraw() {
                sGlobalFrameCounter++;
                if (DEBUG) {
                    long newTime = System.currentTimeMillis();
                    Log.d("FirstFrameAnimatorHelper", "TICK " + (newTime - mTime));
                    mTime = newTime;
                }
            }
        };
    view.getViewTreeObserver().addOnDrawListener(sGlobalDrawListener);
    sVisible = true;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:19,代码来源:FirstFrameAnimatorHelper.java

示例8: startWithText

import android.view.ViewTreeObserver; //导入依赖的package包/类
/**
 * 根据字符串,启动翻页公告
 *
 * @param notice       字符串
 * @param inAnimResId  进入动画的resID
 * @param outAnimResID 离开动画的resID
 */
@SuppressWarnings("deprecation")
public void startWithText(final String notice, final @AnimRes int inAnimResId, final @AnimRes int outAnimResID) {
    if (TextUtils.isEmpty(notice)) return;
    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            startWithFixedWidth(notice, inAnimResId, outAnimResID);
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:MarqueeView.java

示例9: getSize

import android.view.ViewTreeObserver; //导入依赖的package包/类
void getSize(SizeReadyCallback cb) {
  int currentWidth = getTargetWidth();
  int currentHeight = getTargetHeight();
  if (isViewStateAndSizeValid(currentWidth, currentHeight)) {
    cb.onSizeReady(currentWidth, currentHeight);
    return;
  }

  // We want to notify callbacks in the order they were added and we only expect one or two
  // callbacks to be added a time, so a List is a reasonable choice.
  if (!cbs.contains(cb)) {
    cbs.add(cb);
  }
  if (layoutListener == null) {
    ViewTreeObserver observer = view.getViewTreeObserver();
    layoutListener = new SizeDeterminerLayoutListener(this);
    observer.addOnPreDrawListener(layoutListener);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ViewTarget.java

示例10: PhotoViewAttacher

import android.view.ViewTreeObserver; //导入依赖的package包/类
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:38,代码来源:PhotoViewAttacher.java

示例11: introAnimate

import android.view.ViewTreeObserver; //导入依赖的package包/类
private void introAnimate()
{
       if (introAnimate)
	{
		root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
		{
			@Override
			public void onGlobalLayout()
			{
				root.getViewTreeObserver().removeOnGlobalLayoutListener(this);
				
				TransitionHelperAbout.startIntroAnim(root, showShadowListener);
				showShadow();
			}
		});
	}
   }
 
开发者ID:MSay2,项目名称:Mire,代码行数:18,代码来源:FragmentAbout.java

示例12: initToolBar

import android.view.ViewTreeObserver; //导入依赖的package包/类
@Override
public void initToolBar() {

    mCommonToolbar.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
                        mCommonToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mCommonToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                    hideToolBarIfVisible();
                }
            });

    showDialog();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ReadEPubActivity.java

示例13: fixLayout

import android.view.ViewTreeObserver; //导入依赖的package包/类
private void fixLayout() {
    if (fragmentView == null) {
        return;
    }
    fragmentView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (fragmentView != null) {
                checkListViewScroll();
                needLayout();
                fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
            }
            return true;
        }
    });
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:17,代码来源:ProfileActivity.java

示例14: registerKeyboardListener

import android.view.ViewTreeObserver; //导入依赖的package包/类
private void registerKeyboardListener() {
    final View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Logger.e("onGlobalLayout");
            if (isKeyboardShown(rootView)) {
                Logger.e("软键盘弹起");
                getViewHolder().get(R.id.span1).setVisibility(View.GONE);
                getViewHolder().get(R.id.span2).setVisibility(View.GONE);
            } else {
                Logger.e("软键盘未弹起");
                getViewHolder().get(R.id.span1).setVisibility(View.INVISIBLE);
                getViewHolder().get(R.id.span2).setVisibility(View.INVISIBLE);
            }
        }
    });
}
 
开发者ID:GcsSloop,项目名称:diycode,代码行数:19,代码来源:LoginActivity.java

示例15: setOverflowButtonColor

import android.view.ViewTreeObserver; //导入依赖的package包/类
public static void setOverflowButtonColor(@NonNull Activity activity,
                                          @Nullable Toolbar toolbar,
                                          final @ColorInt int color) {
    if (toolbar != null && toolbar.getTag() != null && ATE.IGNORE_TAG.equals(toolbar.getTag()))
        return; // ignore tag was set, don't update the overflow
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final View target = toolbar != null ? toolbar :
            (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<>();
            target.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) return;
            final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
            overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color));
            removeOnGlobalLayoutListener(target, this);
        }
    });
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:23,代码来源:ATEUtil.java


注:本文中的android.view.ViewTreeObserver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。