linearLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
linearLayout.setBackgroundColor(Color.GREEN);
View view = linearLayout.findViewById(R.id.view_right);
// mCOUIToolTips.showWithDirection(view, COUIToolTips.DEFAULT_ALIGN_DIRECTION);
// mCOUIToolTips.showAtLocation()
int[] location = new int[2];
view.getLocationOnScreen(location);
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int popupHeight = view.getMeasuredHeight();
int popupWidth = view.getMeasuredWidth();
//在控件上方显示
// mCOUIToolTips.show(view);
// mCOUIToolTips.showAtLocation(view, Gravity.NO_GRAVITY, (location[0] + view.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);
linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
LogUtils.d(TAG, "onGlobalLayout");
}
}
);
记住一定要移除
linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);