本文整理匯總了Java中android.view.ViewTreeObserver.isAlive方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewTreeObserver.isAlive方法的具體用法?Java ViewTreeObserver.isAlive怎麽用?Java ViewTreeObserver.isAlive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.ViewTreeObserver
的用法示例。
在下文中一共展示了ViewTreeObserver.isAlive方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cancel
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
void cancel() {
creator.clearTag();
callback = null;
ImageView target = this.target.get();
if (target == null) {
return;
}
this.target.clear();
target.removeOnAttachStateChangeListener(this);
ViewTreeObserver vto = target.getViewTreeObserver();
if (vto.isAlive()) {
vto.removeOnPreDrawListener(this);
}
}
示例2: cleanup
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
* Clean-up the resources attached to this object. This needs to be called when the ImageView is
* no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or
* from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
* {@link uk.co.senab.photoview.PhotoView}.
*/
@SuppressWarnings("deprecation")
public void cleanup() {
if (null == mImageView) {
return; // cleanup already done
}
final ImageView imageView = mImageView.get();
if (null != imageView) {
// Remove this as a global layout listener
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (null != observer && observer.isAlive()) {
observer.removeGlobalOnLayoutListener(this);
}
// Remove the ImageView's reference to this
imageView.setOnTouchListener(null);
// make sure a pending fling runnable won't be run
cancelFling();
}
if (null != mGestureDetector) {
mGestureDetector.setOnDoubleTapListener(null);
}
// Clear listeners too
mMatrixChangeListener = null;
mPhotoTapListener = null;
mViewTapListener = null;
// Finally, clear ImageView
mImageView = null;
}
示例3: startAnimation
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void startAnimation() {
rootLayout = (CoordinatorLayout) findViewById(R.id.parent_layout);
rootLayout.setVisibility(View.INVISIBLE);
ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
circularRevealActivity();
else
rootLayout.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
}
示例4: cleanup
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public void cleanup() {
if (this.mImageView != null) {
ImageView imageView = (ImageView) this.mImageView.get();
if (imageView != null) {
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (observer != null && observer.isAlive()) {
observer.removeGlobalOnLayoutListener(this);
}
imageView.setOnTouchListener(null);
cancelFling();
}
if (this.mGestureDetector != null) {
this.mGestureDetector.setOnDoubleTapListener(null);
}
this.mMatrixChangeListener = null;
this.mPhotoTapListener = null;
this.mViewTapListener = null;
this.mImageView = null;
}
}
示例5: cleanup
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
* Clean-up the resources attached to this object. This needs to be called when the ImageView is
* no longer used. A good example is from {@link View#onDetachedFromWindow()} or
* from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
*/
@SuppressWarnings("deprecation")
public void cleanup() {
if (null == mImageView) {
return; // cleanup already done
}
final ImageView imageView = mImageView.get();
if (null != imageView) {
// Remove this as a global layout listener
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (null != observer && observer.isAlive()) {
observer.removeGlobalOnLayoutListener(this);
}
// Remove the ImageView's reference to this
imageView.setOnTouchListener(null);
// make sure a pending fling runnable won't be run
cancelFling();
}
if (null != mGestureDetector) {
mGestureDetector.setOnDoubleTapListener(null);
}
// Clear listeners too
mMatrixChangeListener = null;
mPhotoTapListener = null;
mViewTapListener = null;
// Finally, clear ImageView
mImageView = null;
}
示例6: scrollToTabAfterLayout
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void scrollToTabAfterLayout(final int tabIndex) {
//from http://stackoverflow.com/a/34780589/3697225
if (mTabLayout != null) {
final ViewTreeObserver observer = mTabLayout.getViewTreeObserver();
if (observer.isAlive()) {
observer.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mTabLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
mTabLayout.getTabAt(tabIndex).select();
}
});
}
}
}
示例7: animateViewAfterMeasured
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void animateViewAfterMeasured(final View view) {
final ViewTreeObserver vto = view.getViewTreeObserver();
if (!vto.isAlive()) {
sharePickerView.setVisibility(GONE);
return;
}
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (view.getHeight() > 0 || view.getWidth() > 0) {
if (vto.isAlive()) {
vto.removeGlobalOnLayoutListener(this);
animateAppear();
}
}
}
});
}
示例8: clearCallbacksAndListener
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
void clearCallbacksAndListener() {
// Keep a reference to the layout listener and remove it here
// rather than having the observer remove itself because the observer
// we add the listener to will be almost immediately merged into
// another observer and will therefore never be alive. If we instead
// keep a reference to the listener and remove it here, we get the
// current view tree observer and should succeed.
ViewTreeObserver observer = view.getViewTreeObserver();
if (observer.isAlive()) {
observer.removeOnPreDrawListener(layoutListener);
}
layoutListener = null;
cbs.clear();
}
示例9: onDetachedFromWindow
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
ActivityChooserModel dataModel = this.mAdapter.getDataModel();
if (dataModel != null) {
dataModel.unregisterObserver(this.mModelDataSetOberver);
}
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.removeGlobalOnLayoutListener(this.mOnGlobalLayoutListener);
}
if (isShowingPopup()) {
dismissPopup();
}
this.mIsAttachedToWindow = false;
}
示例10: toggle
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void toggle(final boolean visible, final boolean animate, boolean force) {
if (mVisible != visible || force) {
mVisible = visible;
int height = getHeight();
if (height == 0 && !force) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ViewTreeObserver currentVto = getViewTreeObserver();
if (currentVto.isAlive()) {
currentVto.removeOnPreDrawListener(this);
}
toggle(visible, animate, true);
return true;
}
});
return;
}
}
int translationY = visible ? 0 : height + getMarginBottom();
if (animate) {
animate().setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
} else {
setTranslationY(translationY);
}
// On pre-Honeycomb a translated view is still clickable, so we need to disable clicks manually
if (!Utils.hasHoneycomb()) {
setClickable(visible);
}
}
}
示例11: dismissPopup
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public boolean dismissPopup() {
if (isShowingPopup()) {
getListPopupWindow().dismiss();
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.removeGlobalOnLayoutListener(this.mOnGlobalLayoutListener);
}
}
return true;
}
示例12: dismissPopup
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
* Dismisses the popup window with activities.
*
* @return True if dismissed, false if already dismissed.
*/
public boolean dismissPopup() {
if (isShowingPopup()) {
getListPopupWindow().dismiss();
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
}
}
return true;
}
示例13: animationReveal
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
protected void animationReveal(Bundle savedInstanceState) {
cx = getResources().getDisplayMetrics().widthPixels - 120;
cy = getResources().getDisplayMetrics().heightPixels - 180;
final View rootLayout = getWindow().getDecorView().getRootView();
if (savedInstanceState == null) {
rootLayout.setVisibility(View.INVISIBLE);
ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
float finalRadius = Math.max(rootLayout.getWidth(), rootLayout.getHeight());
// create the animator for this view (the start radius is zero)
Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, 0, finalRadius);
circularReveal.setDuration(revealTime);
// make the view visible and start the animation
rootLayout.setVisibility(View.VISIBLE);
circularReveal.start();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
}
}
示例14: toggle
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void toggle(final boolean visible, final boolean animate, boolean force) {
if (mVisible != visible || force) {
mVisible = visible;
int height = getHeight();
if (height == 0 && !force) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ViewTreeObserver currentVto = getViewTreeObserver();
if (currentVto.isAlive()) {
currentVto.removeOnPreDrawListener(this);
}
toggle(visible, animate, true);
return true;
}
});
return;
}
}
int translationY = visible ? 0 : height + mAddButton.getMarginBottom();
if (animate) {
ViewPropertyAnimator.animate(this).setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
} else {
ViewHelper.setTranslationY(this, translationY);
}
// On pre-Honeycomb a translated view is still clickable, so we need to disable clicks manually
if (!hasHoneycombApi()) {
setClickable(visible);
}
}
}
示例15: toggle
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private void toggle(final boolean visible, final boolean animate, boolean force) {
if (mVisible != visible || force) {
mVisible = visible;
int height = getHeight();
if (height == 0 && !force) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto.isAlive()) {
// view樹完成測量並且分配空間而繪製過程還沒有開始的時候播放動畫。
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ViewTreeObserver currentVto = getViewTreeObserver();
if (currentVto.isAlive()) {
currentVto.removeOnPreDrawListener(this);
}
toggle(visible, animate, true);
return true;
}
});
return;
}
}
int translationY = visible ? 0 : height;
if (animate) {
animate().setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
} else {
ViewCompat.setTranslationY(this, translationY);
}
}
}