List of usage examples for android.widget FrameLayout getViewTreeObserver
public ViewTreeObserver getViewTreeObserver()
From source file:com.harlan.jxust.ui.view.bottombar.BottomBarBadge.java
protected BottomBarBadge(Context context, int position, final View tabToAddTo, // Rhyming accidentally! That's a Smoove Move! int backgroundColor) { super(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); setLayoutParams(params);/*from w w w . j a v a 2 s . com*/ setGravity(Gravity.CENTER); MiscUtils.setTextAppearance(this, R.style.BB_BottomBarBadge_Text); int three = MiscUtils.dpToPixel(context, 3); ShapeDrawable backgroundCircle = BadgeCircle.make(three * 3, backgroundColor); setPadding(three, three, three, three); setBackgroundCompat(backgroundCircle); FrameLayout container = new FrameLayout(context); container.setLayoutParams(params); ViewGroup parent = (ViewGroup) tabToAddTo.getParent(); parent.removeView(tabToAddTo); container.addView(tabToAddTo); container.addView(this); parent.addView(container, position); container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { adjustPositionAndSize(tabToAddTo); } }); }
From source file:com.community.yuequ.bottombar.BottomBarBadge.java
private void wrapTabAndBadgeInSameContainer(final BottomBarTab tab) { ViewGroup tabContainer = (ViewGroup) tab.getParent(); tabContainer.removeView(tab);/*from w w w. j a v a 2 s . c om*/ final FrameLayout badgeContainer = new FrameLayout(getContext()); badgeContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); badgeContainer.addView(tab); badgeContainer.addView(this); tabContainer.addView(badgeContainer, tab.getIndexInTabContainer()); badgeContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { badgeContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); adjustPositionAndSize(tab); } }); }