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


Java OnGlobalLayoutListener类代码示例

本文整理汇总了Java中android.view.ViewTreeObserver.OnGlobalLayoutListener的典型用法代码示例。如果您正苦于以下问题:Java OnGlobalLayoutListener类的具体用法?Java OnGlobalLayoutListener怎么用?Java OnGlobalLayoutListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createSwipeNeighborLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(neighbor.getTab());

            if (view != null) {
                float position;

                if (dragDistance > 0) {
                    position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
                } else {
                    position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
                }

                view.setX(position);
            }
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:37,代码来源:TabletTabSwitcherLayout.java

示例2: createAddSelectedTabLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to show a tab as the currently selected
 * one, once it view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which has been added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createAddSelectedTabLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, item,
                    getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE));
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
                    getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, item, DragState.NONE));
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 1);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 1);
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:34,代码来源:PhoneTabSwitcherLayout.java

示例3: createRevealLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to start a reveal animation to add a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param revealAnimation
 *         The reveal animation, which should be started, as an instance of the class {@link
 *         RevealAnimation}. The reveal animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createRevealLayoutListener(@NonNull final AbstractItem item,
                                                          @NonNull final RevealAnimation revealAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();
            float x = revealAnimation.getX();
            float y = revealAnimation.getY() + tabTitleContainerHeight;
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.X_AXIS, item, x);
            getArithmetics().setPivot(Axis.Y_AXIS, item, y);
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 0);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 0);
            animateReveal(item, revealAnimation);
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:38,代码来源:PhoneTabSwitcherLayout.java

示例4: setListenerToRootView

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
public void setListenerToRootView() {
    final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
                if (isOpened == false) {
                    //Do two things, make the view top visible and the editText smaller
                }
                isOpened = true;
            } else if (isOpened == true) {
                isOpened = false;
                final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:VLayoutActivity.java

示例5: notifyDataSetChanged

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++) {
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:23,代码来源:PagerSlidingTabStrip.java

示例6: changeViewPageHight

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
@SuppressLint({"NewApi"})
private void changeViewPageHight() {
    final int w = MeasureSpec.makeMeasureSpec(0, 0);
    final int h = MeasureSpec.makeMeasureSpec(0, 0);
    this.mRegisterViewPager.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(this) {
        final /* synthetic */ RegisterActivity this$0;

        public void onGlobalLayout() {
            if (VERSION.SDK_INT >= 16) {
                this.this$0.mRegisterViewPager.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                this.this$0.mRegisterViewPager.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            View view = this.this$0.mRegisterViewPager.getChildAt(this.this$0.mRegisterViewPager.getCurrentItem());
            view.measure(w, h);
            LayoutParams params = new LayoutParams(-1, -2);
            params.height = view.getMeasuredHeight();
            this.this$0.mRegisterViewPager.setLayoutParams(params);
        }
    });
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:RegisterActivity.java

示例7: notifyDataSetChanged

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * You can invoke the method if you need to rearrange.
 */
public void notifyDataSetChanged() {
    mTabCount = mTabTitles.size();
    mTabContainer.removeAllViews();
    if (mTabTitles != null && mTabTitles.size() > 0) {
        for (int i = 0; i < mTabTitles.size(); i++) {
            addTextTab(i, mTabTitles.get(i));
        }
    }
    refreshTabs();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        public void onGlobalLayout() {
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
            scrollToChild(mPosition, 0);
        }
    });
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:21,代码来源:HorizontalTabBar.java

示例8: inflateView

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Inflates the view, which is used to visualize a specific item.
 *
 * @param item
 *         The item, whose view should be inflated, as an instance of the class {@link
 *         AbstractItem}. The item may not be null
 * @param listener
 *         The layout listener, which should be notified, when the view has been inflated, as an
 *         instance of the type {@link OnGlobalLayoutListener} or null, if no listener should be
 *         notified
 * @param params
 *         An array, which contains optional parameters, which should be passed to the view
 *         recycler, which is used to inflate the view, as an {@link Integer} array or null, if
 *         no optional parameters should be used
 */
protected final void inflateView(@NonNull final AbstractItem item,
                                 @Nullable final OnGlobalLayoutListener listener,
                                 @NonNull final Integer... params) {
    Pair<View, Boolean> pair = getTabViewRecycler().inflate(item, params);

    if (listener != null) {
        boolean inflated = pair.second;

        if (inflated) {
            View view = pair.first;
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:33,代码来源:AbstractTabSwitcherLayout.java

示例9: inflateContent

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Inflates the content, which is associated with a specific tab.
 *
 * @param tab
 *         The tab, whose content should be inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @param listener
 *         The layout listener, which should be notified, when the view has been inflated, as an
 *         instance of the type {@link OnGlobalLayoutListener} or null, if no listener should be
 *         notified
 */
private void inflateContent(@NonNull final Tab tab,
                            @Nullable final OnGlobalLayoutListener listener) {
    Pair<View, Boolean> pair = contentViewRecycler.inflate(tab);
    View view = pair.first;

    if (listener != null) {
        boolean inflated = pair.second;

        if (inflated) {
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:28,代码来源:TabletTabSwitcherLayout.java

示例10: createInflateViewLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of an
 * item, once its view has been inflated.
 *
 * @param item
 *         The item, whose view should be adapted, as an instance of the class {@link
 *         AbstractItem}. The item may not be null
 * @param dragging
 *         True, if the item is currently being dragged, false otherwise
 * @param layoutListener
 *         The layout lister, which should be notified, when the created listener is invoked, as
 *         an instance of the type {@link OnGlobalLayoutListener} or null, if no listener should
 *         be notified
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createInflateViewLayoutListener(@NonNull final AbstractItem item,
                                                               final boolean dragging,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            updateView(item, dragging);

            if (layoutListener != null) {
                layoutListener.onGlobalLayout();
            }
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:34,代码来源:TabletTabSwitcherLayout.java

示例11: createContentLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to position the content of a tab, after
 * it has been inflated.
 *
 * @param tab
 *         The tab, whose content has been inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createContentLayoutListener(@NonNull final Tab tab) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(tab);

            if (view != null) {
                view.setX(0);
            }
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:26,代码来源:TabletTabSwitcherLayout.java

示例12: createPeekLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to start a peek animation to add a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param peekAnimation
 *         The peek animation, which should be started, as an instance of the class {@link
 *         PeekAnimation}. The peek animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
private OnGlobalLayoutListener createPeekLayoutListener(@NonNull final AbstractItem item,
                                                        @NonNull final PeekAnimation peekAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            float peekPosition =
                    getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false) * 0.66f;
            animatePeek(item, duration, interpolator, peekPosition, peekAnimation);
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:34,代码来源:PhoneTabSwitcherLayout.java

示例13: createSwipeNeighborLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            float position;

            if (dragDistance > 0) {
                position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
            } else {
                position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
            }

            getArithmetics().setPosition(Axis.X_AXIS, neighbor, position);
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:33,代码来源:PhoneTabSwitcherLayout.java

示例14: createBottomMarginLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to adapt the bottom margin of a tab, once
 * its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, whose view should be adapted, as an instance
 *         of the class {@link AbstractItem}. The item may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
private OnGlobalLayoutListener createBottomMarginLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();

            if (tabViewBottomMargin == -1) {
                tabViewBottomMargin = calculateBottomMargin(item);
            }

            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            layoutParams.bottomMargin = tabViewBottomMargin;
            view.setLayoutParams(layoutParams);
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:31,代码来源:PhoneTabSwitcherLayout.java

示例15: createInflateViewLayoutListener

import android.view.ViewTreeObserver.OnGlobalLayoutListener; //导入依赖的package包/类
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, whose view should be adapted, as an instance
 *         of the class {@link AbstractItem}. The item may not be null
 * @param dragging
 *         True, if the item is currently being dragged, false otherwise
 * @param layoutListener
 *         The layout lister, which should be notified, when the created listener is invoked, as
 *         an instance of the type {@link OnGlobalLayoutListener} or null, if no listener should
 *         be notified
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createInflateViewLayoutListener(@NonNull final AbstractItem item,
                                                               final boolean dragging,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            adaptViewSize(item);
            updateView(item, dragging);

            if (layoutListener != null) {
                layoutListener.onGlobalLayout();
            }
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:35,代码来源:PhoneTabSwitcherLayout.java


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