当前位置: 首页>>代码示例>>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;未经允许,请勿转载。