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


Java ViewTreeObserver.addOnGlobalLayoutListener方法代码示例

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


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

示例1: onCreate

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shoppingcart);
    initView();
    getData();

    ViewTreeObserver viewTreeObserver = iv_shop_cart.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            iv_shop_cart.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            mShoppingCartWidth = iv_shop_cart.getMeasuredWidth();
        }
    });

}
 
开发者ID:Lichenwei-Dev,项目名称:BezierView,代码行数:18,代码来源:ShoppingCartActivity.java

示例2: onLaidOut

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

示例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);
                }
            }
        });
    }
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:22,代码来源:Home.java

示例4: setOverflowButtonColor

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
            overflow.setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
开发者ID:IdeaTrackerPlus,项目名称:IdeaTrackerPlus,代码行数:27,代码来源:ToolbarColorizeHelper.java

示例5: PhotoViewAttacher

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:37,代码来源:PhotoViewAttacher.java

示例6: PhotoViewAttacher

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:38,代码来源:PhotoViewAttacher.java

示例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();
                }
            }
        }
    });
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:20,代码来源:ShareView.java

示例8: onCreate

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

    chessBoardFrame = (FrameLayout) findViewById(R.id.frame_layout);
    chessboardView = (CheckeredGameboardView) findViewById(R.id.boardgameview_chess);
    gridSize = chessboardView.getGridSize();
    figuren = new ImageView[gridSize][gridSize];
    setFieldFromFEN(board.getBoard());
    final ViewTreeObserver vto = chessboardView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            addImages();
            chessboardView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
    chessboardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (!stateAllowClick) return false;
            if (event.getAction() == MotionEvent.ACTION_UP) {
                Tuple<Integer, Integer> tuple = chessboardView.getSquareFromTouch((int) event.getX(), (int) event.getY());
                if (tuple != null) {
                    onSquareClicked(tuple);
                }
            }
            return true;
        }
    });
    setupRecyclerView();
}
 
开发者ID:android-gamecollection,项目名称:gamecollection,代码行数:33,代码来源:Chess.java

示例9: addOnGlobalLayoutListener

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

示例10: initSlider

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private View initSlider(UltimateRecyclerView listview) {
    final View view = LayoutInflater.from(getApplication()).inflate(R.layout.list_item_header, null, false);
    final ViewTreeObserver vto = listview.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            //Log.d("vto", "globallayout");
            final SliderLayout sl = (SliderLayout) view.findViewById(R.id.header_slider);
            try {
                sl.setOffscreenPageLimit(1);
                sl.setSliderTransformDuration(500, new LinearOutSlowInInterpolator());
                sl.setPresetTransformer(TransformerL.Default);
                sl.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
                sl.getPagerIndicator().setDefaultIndicatorColor(R.color.accent, R.color.primaryDark);
                sl.getPagerIndicator().setVisibility(View.GONE);
                setup_double_faces(sl);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });


    return view;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:SliderHeader.java

示例11: PhotoViewAttacher

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2,
                                       float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:57,代码来源:PhotoViewAttacher.java

示例12: onCreate

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setAmbientEnabled();
    drawer_itemArrayList = initializeScreenSystem();
    mSelectedScreen = 0;


    // Register the local broadcast receiver
    IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND);
    MessageReceiver messageReceiver = new MessageReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, messageFilter);

    // Initialize content to first screen.
    mDrinkFragment = new DrinkWaterFragment();
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, mDrinkFragment).commit();

    // Main Wearable Drawer Layout that holds all the content
    mWearableDrawerLayout = (WearableDrawerLayout) findViewById(R.id.drawer_layout);

    // Top Navigation Drawer
    mWearableNavigationDrawer =
            (WearableNavigationDrawer) findViewById(R.id.top_navigation_drawer);

    mWearableNavigationDrawer.setAdapter(new NavigationAdapter(this));

    // Bottom Action Drawer
    mWearableActionDrawer =
            (WearableActionDrawer) findViewById(R.id.bottom_action_drawer);

    mWearableActionDrawer.setOnMenuItemClickListener(this);

    // Temporarily peeks the navigation and action drawers to ensure the user is aware of them.
    ViewTreeObserver observer = mWearableDrawerLayout.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mWearableDrawerLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            mWearableDrawerLayout.peekDrawer(Gravity.TOP);
            mWearableDrawerLayout.peekDrawer(Gravity.BOTTOM);
        }
    });
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:46,代码来源:MainActivity.java

示例13: getWidgetWH

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

示例14: getViewHeight

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

示例15: showPages

import android.view.ViewTreeObserver; //导入方法依赖的package包/类
protected void showPages()
{
	LinearLayout pages = (LinearLayout) findViewById(R.id.pages_container);
	if (null == pages)
		return;

	if (pages.getVisibility() == View.VISIBLE)
		return;

	pages.setVisibility(View.VISIBLE);

	final ViewTreeObserver observer = mDocView.getViewTreeObserver();
	observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
	{
		@Override
		public void onGlobalLayout()
		{
			observer.removeOnGlobalLayoutListener(this);
			mDocView.onShowPages();
		}
	});

	final ViewTreeObserver observer2 = getViewTreeObserver();
	observer2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
	{
		@Override
		public void onGlobalLayout()
		{
			observer2.removeOnGlobalLayoutListener(this);
			mDocPagesView.onOrientationChange();
			int page = mDocView.getMostVisiblePage();
			mDocPagesView.setCurrentPage(page);
			mDocPagesView.scrollToPage(page);
		}
	});
}
 
开发者ID:ArtifexSoftware,项目名称:mupdf-android-viewer-nui,代码行数:37,代码来源:DocActivityView.java


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