當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。