當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewTreeObserver.OnGlobalLayoutListener方法代碼示例

本文整理匯總了Java中android.view.ViewTreeObserver.OnGlobalLayoutListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewTreeObserver.OnGlobalLayoutListener方法的具體用法?Java ViewTreeObserver.OnGlobalLayoutListener怎麽用?Java ViewTreeObserver.OnGlobalLayoutListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.ViewTreeObserver的用法示例。


在下文中一共展示了ViewTreeObserver.OnGlobalLayoutListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doMonitorSoftKeyWord

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
 * 判斷軟鍵盤是否彈出
 * * @param rootView
 *
 * @param listener 備注:在不用的時候記得移除OnGlobalLayoutListener
 */
public static ViewTreeObserver.OnGlobalLayoutListener doMonitorSoftKeyWord(final View rootView, final OnSoftKeyWordShowListener listener) {
    final ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final Rect rect = new Rect();
            rootView.getWindowVisibleDisplayFrame(rect);
            final int screenHeight = rootView.getRootView().getHeight();
            Log.e("TAG", rect.bottom + "#" + screenHeight);
            final int heightDifference = screenHeight - rect.bottom;
            boolean visible = heightDifference > screenHeight / 3;
            if (listener != null)
                listener.hasShow(visible);
        }
    };
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return layoutListener;
}
 
開發者ID:auv1107,項目名稱:TextEmoji,代碼行數:24,代碼來源:SoftKeyboardUtils.java

示例2: setupDialog

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    mContentView = View.inflate(getContext(), R.layout.changelog_dialog_content, null);
    dialog.setContentView(mContentView);
    unbinder = ButterKnife.bind(this, mContentView);
    Hawk.put("WHATS_NEW_VERSION", BuildConfig.VERSION_CODE);
    mCancel.setVisibility(View.GONE);
    mTitle.setText(R.string.changelog);
    mMessage.setText(getString(R.string.changelog_detail));

    mListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            View parent = (View) mContentView.getParent();
            BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
            behavior.setPeekHeight(mContentView.getMeasuredHeight());
            CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) mContentView.getParent()).getLayoutParams();
            layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;

            removeGlobalLayoutListener();
        }
    };
    mContentView.getViewTreeObserver().addOnGlobalLayoutListener(mListener);
}
 
開發者ID:alphater,項目名稱:garras,代碼行數:27,代碼來源:ChangelogBottomSheetDialog.java

示例3: execute

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@Override
public void execute() {
    Activity activity = activityRef.get();
    ViewTreeObserver.OnGlobalLayoutListener listener = listenerRef.get();

    if (activity != null && listener != null) {
        View root = SoftKeyboardDetector.getActivityRoot(activity);
        if (root != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                root.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
            } else {
                root.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
            }
        }
    }

    activityRef.clear();
    listenerRef.clear();
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:20,代碼來源:SoftKeyboardDetector.java

示例4: removeOnGlobalLayoutListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@TargetApi(JELLY_BEAN)
static void removeOnGlobalLayoutListener(final View v, final ViewTreeObserver.OnGlobalLayoutListener listener) {
    if (SDK_INT < JELLY_BEAN) {
        //noinspection deprecation
        v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
    } else {
        v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
    }
}
 
開發者ID:apradanas,項目名稱:prismoji-android,代碼行數:10,代碼來源:Utils.java

示例5: removeOnGlobalLayoutListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private static void removeOnGlobalLayoutListener(ViewTreeObserver observer, ViewTreeObserver.OnGlobalLayoutListener listener) {
    if (observer == null) {
        return ;
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        observer.removeGlobalOnLayoutListener(listener);
    } else {
        observer.removeOnGlobalLayoutListener(listener);
    }
}
 
開發者ID:jphacks,項目名稱:TK_1701,代碼行數:12,代碼來源:LookActivity.java

示例6: attach

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@Override
public ViewTreeObserver.OnGlobalLayoutListener attach(final Activity activity, IPanelLayout target,
                                                            OnKeyboardListener listener) {
    final ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    final boolean isFullScreen = ViewUtil.isFullScreen(activity);
    final boolean isTranslucentStatus = ViewUtil.isTranslucentStatus(activity);
    final boolean isFitSystemWindows = ViewUtil.isFitsSystemWindows(activity);

    final Display display = activity.getWindowManager().getDefaultDisplay();
    final int screenHeight;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        final Point screenSize = new Point();
        display.getSize(screenSize);
        screenHeight = screenSize.y;
    } else {
        screenHeight = display.getHeight();
    }

    ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener = new KeyboardStatusListener(
            isFullScreen,
            isTranslucentStatus,
            isFitSystemWindows,
            contentView,
            target,
            listener,
            screenHeight);

    contentView.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
    return globalLayoutListener;
}
 
開發者ID:nickyangjun,項目名稱:EasyEmoji,代碼行數:32,代碼來源:KeyboardManagerImpl.java

示例7: detach

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void detach(Activity activity, ViewTreeObserver.OnGlobalLayoutListener l) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        contentView.getViewTreeObserver().removeOnGlobalLayoutListener(l);
    } else {
        contentView.getViewTreeObserver().removeGlobalOnLayoutListener(l);
    }
}
 
開發者ID:nickyangjun,項目名稱:EasyEmoji,代碼行數:11,代碼來源:KeyboardManagerImpl.java

示例8: removeGlobalLayoutObserver

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public static void removeGlobalLayoutObserver(final ViewTreeObserver observer,
        ViewTreeObserver.OnGlobalLayoutListener layoutListener) {
    if (Build.VERSION.SDK_INT < 16) {
        observer.removeGlobalOnLayoutListener(layoutListener);
    } else {
        observer.removeOnGlobalLayoutListener(layoutListener);
    }
}
 
開發者ID:lurbas,項目名稱:ListItemView,代碼行數:9,代碼來源:ViewUtils.java

示例9: notifyListeners

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
 * Notify listeners
 */
private void notifyListeners() {
    if (listener == null) return;

    listener.onAnimationStart();
    if (isExpanded) {
        listener.onPreOpen();
    } else {
        listener.onPreClose();
    }
    mGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(mGlobalLayoutListener);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(mGlobalLayoutListener);
            }

            listener.onAnimationEnd();
            if (isExpanded) {
                listener.onOpened();
            } else {
                listener.onClosed();
            }
        }
    };
    getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:32,代碼來源:ExpandableLinearLayout.java

示例10: removeGlobalOnLayoutListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@TargetApi(AndroidVersionCodes.JELLY_BEAN)
public static void removeGlobalOnLayoutListener(ViewTreeObserver mViewTreeObserver, ViewTreeObserver.OnGlobalLayoutListener listener) {
    if (Build.VERSION.SDK_INT < AndroidVersionCodes.JELLY_BEAN) {
        mViewTreeObserver.removeGlobalOnLayoutListener(listener);
    } else {
        mViewTreeObserver.removeOnGlobalLayoutListener(listener);
    }
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:9,代碼來源:AndroidUtilsCompat.java

示例11: removeLayoutListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
private static void removeLayoutListener(View view, ViewTreeObserver.OnGlobalLayoutListener listener) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
    } else {
        //noinspection deprecation
        view.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:9,代碼來源:ATEUtil.java

示例12: setVisibilityEventListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
/**
 * Set keyboard visibility change event listener.
 *
 * @param activity Activity
 * @param listener KeyboardVisibilityEventListener
 */
@SuppressWarnings("deprecation")
public static void setVisibilityEventListener(final Activity activity,
                                              final KeyboardVisibilityEventListener listener) {

    if (activity == null) {
        throw new NullPointerException("Parameter:activity must not be null");
    }

    if (listener == null) {
        throw new NullPointerException("Parameter:listener must not be null");
    }

    final View activityRoot = QMUIViewHelper.getActivityRoot(activity);

    final ViewTreeObserver.OnGlobalLayoutListener layoutListener =
            new ViewTreeObserver.OnGlobalLayoutListener() {

                private final Rect r = new Rect();

                private final int visibleThreshold = Math.round(
                        QMUIDisplayHelper.dp2px(activity, KEYBOARD_VISIBLE_THRESHOLD_DP));

                private boolean wasOpened = false;

                @Override
                public void onGlobalLayout() {
                    activityRoot.getWindowVisibleDisplayFrame(r);

                    int heightDiff = activityRoot.getRootView().getHeight() - r.height();

                    boolean isOpen = heightDiff > visibleThreshold;

                    if (isOpen == wasOpened) {
                        // keyboard state has not changed
                        return;
                    }

                    wasOpened = isOpen;

                    listener.onVisibilityChanged(isOpen);
                }
            };
    activityRoot.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    activity.getApplication()
            .registerActivityLifecycleCallbacks(new QMUIActivityLifecycleCallbacks(activity) {
                @Override
                protected void onTargetActivityDestroyed() {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        activityRoot.getViewTreeObserver()
                                .removeOnGlobalLayoutListener(layoutListener);
                    } else {
                        activityRoot.getViewTreeObserver()
                                .removeGlobalOnLayoutListener(layoutListener);
                    }
                }
            });
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:64,代碼來源:QMUIKeyboardHelper.java

示例13: onCreate

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        if (mBubbleLayout == null)
        {
            mBubbleLayout = new BubbleLayout(getContext());
        }
        if (mAddView != null)
        {
            mBubbleLayout.addView(mAddView);
        }
        setContentView(mBubbleLayout);

        final Window window = getWindow();
        if (window == null) return;
        if (mSoftShowUp)
        {
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        }
        window.setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        onAutoPosition();

        setLook();
//        mBubbleLayout.post(new Runnable()
//        {
//            @Override
//            public void run()
//            {
//                dialogPosition();
//            }
//        });

        mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener()
        {
            int lastWidth, lastHeight;
            @Override
            public void onGlobalLayout()
            {
                if (lastWidth == mBubbleLayout.getWidth() && lastHeight == mBubbleLayout.getHeight()) return;
                dialogPosition();
                lastWidth = mBubbleLayout.getWidth();
                lastHeight = mBubbleLayout.getHeight();
            }
        };

        mBubbleLayout.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);


        mBubbleLayout.setOnClickEdgeListener(new BubbleLayout.OnClickEdgeListener()
        {
            @Override
            public void edge()
            {
                if (BubbleDialog.this.mCancelable)
                {
                    dismiss();
                }
            }
        });
    }
 
開發者ID:xujiaji,項目名稱:HappyBubble,代碼行數:63,代碼來源:BubbleDialog.java

示例14: registerKeyboardEventListener

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public static Unregister registerKeyboardEventListener(Activity activity, final OnKeyboardEventListener listener) {
    if (activity == null || listener == null) {
        WXLogUtils.e("Activity or listener is null!");
        return null;
    }

    if (activity.getWindow() != null) {
        WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
        if (attributes != null) {
            int softInputMode = attributes.softInputMode;
            if (softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
                    || softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
                WXLogUtils.e("SoftKeyboard detector can't work with softInputMode is SOFT_INPUT_ADJUST_NOTHING or SOFT_INPUT_ADJUST_PAN");
                return null;
            }
        }
    }

    final View activityRoot = getActivityRoot(activity);

    if (activityRoot == null) {
        WXLogUtils.e("Activity root is null!");
        return null;
    }

    final ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

        private final Rect visibleFrame = new Rect();
        private final int threshold = WXViewUtils.dip2px(KEYBOARD_VISIBLE_THRESHOLD_DIP);
        private boolean wasKeyboardOpened = false;

        @Override
        public void onGlobalLayout() {
            activityRoot.getWindowVisibleDisplayFrame(visibleFrame);
            int heightDiff = activityRoot.getRootView().getHeight() - visibleFrame.height();
            boolean isOpen = heightDiff > threshold;
            if (isOpen == wasKeyboardOpened) {
                return;
            }

            wasKeyboardOpened = isOpen;
            listener.onKeyboardEvent(isOpen);
        }
    };

    activityRoot.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return new DefaultUnRegister(activity, layoutListener);
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:49,代碼來源:SoftKeyboardDetector.java

示例15: DefaultUnRegister

import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public DefaultUnRegister(Activity activity, ViewTreeObserver.OnGlobalLayoutListener listener) {
    this.activityRef = new WeakReference<>(activity);
    this.listenerRef = new WeakReference<>(listener);
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:5,代碼來源:SoftKeyboardDetector.java


注:本文中的android.view.ViewTreeObserver.OnGlobalLayoutListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。