@Override public boolean onPreDraw() { lv.getViewTreeObserver().removeOnPreDrawListener(this); mArrowDrawable.setMode(ArrowDrawable.MODE_UP, true); return true; } });
@Override public void onGlobalLayout() { ListView lv = mReplacementPopup.getListView(); ViewTreeObserver observer = lv.getViewTreeObserver(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) observer.removeOnGlobalLayoutListener(this); else observer.removeGlobalOnLayoutListener(this); View v = lv.getChildAt(0); v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mReplacementPopup.setContentWidth(v.getMeasuredWidth()); int[] popupLocation = new int[2]; lv.getLocationOnScreen(popupLocation); int[] inputLocation = new int[2]; mInputView.getLocationOnScreen(inputLocation); Drawable background = mReplacementPopup.getPopup().getBackground(); Rect backgroundPadding = new Rect(); int verticalOffset; int horizontalOffset = inputLocation[0] + (int)mSelectedSpan.mX - (popupLocation[0] + backgroundPadding.left); if(background != null) background.getPadding(backgroundPadding); if(inputLocation[1] < popupLocation[1]) //popup show at bottom verticalOffset = inputLocation[1] + mSelectedSpan.mY - (popupLocation[1] + backgroundPadding.top); else verticalOffset = inputLocation[1] + mSelectedSpan.mY + mSpanHeight - (popupLocation[1] + lv.getHeight() - backgroundPadding.bottom); mReplacementPopup.setVerticalOffset(verticalOffset); mReplacementPopup.setHorizontalOffset(horizontalOffset); mReplacementPopup.show(); } });
private void showPopup(){ if (!mPopup.isShowing()){ mPopup.show(); final ListView lv = mPopup.getListView(); if(lv != null){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setSelection(getSelectedItemPosition()); if(mArrowDrawable != null && mArrowAnimSwitchMode) lv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { lv.getViewTreeObserver().removeOnPreDrawListener(this); mArrowDrawable.setMode(ArrowDrawable.MODE_UP, true); return true; } }); } } }
mReplacementPopup.show(); mReplacementPopup.getListView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() {