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


Java View.getViewTreeObserver方法代码示例

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


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

示例1: onLaidOut

import android.view.View; //导入方法依赖的package包/类
/**
 * Executes the given {@link Runnable} when the view is laid out
 **/
public static void onLaidOut(final View view, final Runnable runnable) {
    if (isLaidOut(view)) {
        runnable.run();
        return;
    }

    final ViewTreeObserver observer = view.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ViewTreeObserver trueObserver;

            if (observer.isAlive()) {
                trueObserver = observer;
            } else {
                trueObserver = view.getViewTreeObserver();
            }

            removeGlobalLayoutObserver(trueObserver, this);
            runnable.run();
        }
    });
}
 
开发者ID:lurbas,项目名称:ListItemView,代码行数:27,代码来源:ViewUtils.java

示例2: setOverflowButtonColor

import android.view.View; //导入方法依赖的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

示例3: onCreate

import android.view.View; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final View layout = findViewById(Window.ID_ANDROID_CONTENT);
    ViewTreeObserver vto = layout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            initUIandEvent();
        }
    });
}
 
开发者ID:AgoraIO,项目名称:OpenLive-Android,代码行数:19,代码来源:BaseActivity.java

示例4: animateViewAfterMeasured

import android.view.View; //导入方法依赖的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();
                }
            }
        }
    });
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:20,代码来源:ShareView.java

示例5: onMapReady

import android.view.View; //导入方法依赖的package包/类
public void onMapReady(GoogleMap googleMap) {
    if (m_gMap == null) {
        m_gMap = googleMap;

        GoogleMap map = getMap();
        if (map == null) {
            MFBUtil.Alert(this, getString(R.string.txtError), getString(R.string.errNoGoogleMaps));
            finish();
            return;
        }

        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        UiSettings settings = map.getUiSettings();
        settings.setCompassEnabled(false);
        settings.setRotateGesturesEnabled(false);
        settings.setScrollGesturesEnabled(true);
        settings.setZoomControlsEnabled(false);
        settings.setZoomGesturesEnabled(true);

        View mapView = getFragmentManager().findFragmentById(R.id.mfbMap).getView();
        if (mapView != null && mapView.getViewTreeObserver() != null && mapView.getViewTreeObserver().isAlive()) {
            mapView.getViewTreeObserver().addOnGlobalLayoutListener(this);
        }

        map.setOnMarkerClickListener(this);
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            map.setMyLocationEnabled(true);
        }
        map.setOnMapLongClickListener(this);

        updateMapElements();
    }
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:34,代码来源:ActFlightMap.java

示例6: addKeyboardVisibilityChangedListener

import android.view.View; //导入方法依赖的package包/类
public static void addKeyboardVisibilityChangedListener(
        @NonNull OnKeyboardVisibilityChangedListener listener, @NonNull Activity activity) {
    final View activityRootView = ((ViewGroup) activity.findViewById(android.R.id.content))
            .getChildAt(0);
    ViewTreeObserver viewTreeObserver = activityRootView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        private final int ESTIMATED_KEYBOARD_SIZE_DP = 100;
        private final Rect r = new Rect();

        @Override
        public void onGlobalLayout() {
            float estimatedKeyboardHeight = DeviceUtils.dpToPx(ESTIMATED_KEYBOARD_SIZE_DP);
            activityRootView.getWindowVisibleDisplayFrame(r);
            int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
            boolean isVisible = (heightDiff >= estimatedKeyboardHeight);
            listener.onVisibilityChanged(isVisible);
        }
    });
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:20,代码来源:KeyboardUtils.java

示例7: addOnGlobalLayoutListener

import android.view.View; //导入方法依赖的package包/类
/**
 * Add an OnGlobalLayoutListener for the view.
 * This is just a convenience method for using {@code ViewTreeObserver.OnGlobalLayoutListener()}.
 * This also handles removing listener when onGlobalLayout is called.
 *
 * @param view     the target view to add global layout listener
 * @param runnable runnable to be executed after the view is laid out
 */
public static void addOnGlobalLayoutListener(final View view, final Runnable runnable) {
    ViewTreeObserver vto = view.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            runnable.run();
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ScrollUtils.java

示例8: getWidgetWH

import android.view.View; //导入方法依赖的package包/类
/**
 * 直接获取控件的宽、高
 * @param view
 * @return int[]
 */
public static int[] getWidgetWH(final View view){
    ViewTreeObserver vto2 = view.getViewTreeObserver();
    vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
        	view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
	return new int[]{view.getWidth(),view.getHeight()};
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:16,代码来源:DisplayUtil.java

示例9: getViewHeight

import android.view.View; //导入方法依赖的package包/类
/**
 * 直接获取控件的宽、高
 * @param view
 * @return int[]
 */
public static int getViewHeight(final View view){
	ViewTreeObserver vto2 = view.getViewTreeObserver();
	vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
			view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
		}
	});
	return view.getHeight();
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:16,代码来源:DisplayUtil.java

示例10: getViewWidth

import android.view.View; //导入方法依赖的package包/类
/**
 * 直接获取控件的宽、高
 * @param view
 * @return int[]
 */
public static int getViewWidth(final View view){
	ViewTreeObserver vto2 = view.getViewTreeObserver();
	vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
			view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
		}
	});
	return view.getWidth();
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:16,代码来源:DisplayUtil.java

示例11: registerListener

import android.view.View; //导入方法依赖的package包/类
private void registerListener(View anchor) {
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:14,代码来源:ActionBarPopupWindow.java

示例12: tryShow

import android.view.View; //导入方法依赖的package包/类
public boolean tryShow() {
    boolean addGlobalListener = false;
    this.mPopup = new ListPopupWindow(this.mContext, null, this.mPopupStyleAttr, this.mPopupStyleRes);
    this.mPopup.setOnDismissListener(this);
    this.mPopup.setOnItemClickListener(this);
    this.mPopup.setAdapter(this.mAdapter);
    this.mPopup.setModal(true);
    View anchor = this.mAnchorView;
    if (anchor == null) {
        return false;
    }
    if (this.mTreeObserver == null) {
        addGlobalListener = true;
    }
    this.mTreeObserver = anchor.getViewTreeObserver();
    if (addGlobalListener) {
        this.mTreeObserver.addOnGlobalLayoutListener(this);
    }
    this.mPopup.setAnchorView(anchor);
    this.mPopup.setDropDownGravity(this.mDropDownGravity);
    if (!this.mHasContentWidth) {
        this.mContentWidth = measureContentWidth();
        this.mHasContentWidth = true;
    }
    this.mPopup.setContentWidth(this.mContentWidth);
    this.mPopup.setInputMethodMode(2);
    this.mPopup.show();
    this.mPopup.getListView().setOnKeyListener(this);
    return true;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:31,代码来源:MenuPopupHelper.java

示例13: animationReveal

import android.view.View; //导入方法依赖的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);
                    }
                }
            });
        }
    }
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:30,代码来源:OperateItemActivityBase.java

示例14: onLaidOut

import android.view.View; //导入方法依赖的package包/类
/**
 * Executes the given {@link java.lang.Runnable} when the view is laid out
 **/
public static void onLaidOut(final View view, final Runnable runnable) {
    if (isLaidOut(view)) {
        runnable.run();
        return;
    }

    final ViewTreeObserver observer = view.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ViewTreeObserver trueObserver;

            if (observer.isAlive()) {
                trueObserver = observer;
            } else {
                trueObserver = view.getViewTreeObserver();
            }

            if (Build.VERSION.SDK_INT >= 16) {
                trueObserver.removeOnGlobalLayoutListener(this);
            } else {
                //noinspection deprecation
                trueObserver.removeGlobalOnLayoutListener(this);
            }
            runnable.run();
        }
    });
}
 
开发者ID:lurbas,项目名称:MaterialMasterDetail,代码行数:32,代码来源:ViewUtils.java

示例15: startAnimation

import android.view.View; //导入方法依赖的package包/类
public static MoveData startAnimation(Context context, final View toView, Bundle transitionBundle, Bundle savedInstanceState, final int duration, final TimeInterpolator interpolator) {
    final TransitionData transitionData = new TransitionData(context, transitionBundle);
    if (transitionData.imageFilePath != null) {
        setImageToView(toView, transitionData.imageFilePath);
    }
    final MoveData moveData = new MoveData();
    moveData.toView = toView;
    moveData.duration = duration;
    if (savedInstanceState == null) {

        ViewTreeObserver observer = toView.getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                toView.getViewTreeObserver().removeOnPreDrawListener(this);

                int[] screenLocation = new int[2];
                toView.getLocationOnScreen(screenLocation);
                moveData.leftDelta = transitionData.thumbnailLeft - screenLocation[0];
                moveData.topDelta = transitionData.thumbnailTop - screenLocation[1];

                moveData.widthScale = (float) transitionData.thumbnailWidth / toView.getWidth();
                moveData.heightScale = (float) transitionData.thumbnailHeight / toView.getHeight();

                runEnterAnimation(moveData, interpolator);

                return true;
            }
        });
    }
    return moveData;
}
 
开发者ID:MSay2,项目名称:Mire,代码行数:34,代码来源:TransitionAnimation.java


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