Java Code Examples for android.support.v7.widget.ListPopupWindow#setHorizontalOffset()

The following examples show how to use android.support.v7.widget.ListPopupWindow#setHorizontalOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolbarSpinner.java    From FilePicker with MIT License 6 votes vote down vote up
public ToolbarSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ToolbarSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
Example 2
Source File: ToolbarSpinner.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
public ToolbarSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ToolbarSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
Example 3
Source File: AlbumsSpinner.java    From AlbumCameraRecorder with MIT License 6 votes vote down vote up
public AlbumsSpinner(@NonNull Context context) {
    // 实例化ListPopupWindow控件
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    // 点击事件
    mListPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
        AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
        if (mOnItemSelectedListener != null) {
            mOnItemSelectedListener.onItemSelected(parent, view, position, id);
        }
    });
}
 
Example 4
Source File: AlbumsSpinner.java    From Matisse with Apache License 2.0 6 votes vote down vote up
public AlbumsSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
Example 5
Source File: MenuPopupHelper.java    From floatingsearchview with Apache License 2.0 5 votes vote down vote up
public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
        if (addGlobalListener) mTreeObserver.addOnGlobalLayoutListener(this);
        mPopup.setAnchorView(anchor);
        mPopup.setDropDownGravity(mDropDownGravity);
    } else {
        return false;
    }
    if (!mHasContentWidth) {
        mContentWidth = measureContentWidth();
        mHasContentWidth = true;
    }
    mPopup.setContentWidth(mContentWidth);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);

    int vertOffset = -mAnchorView.getHeight() + Util.dpToPx(4);
    int horizontalOffset = -mContentWidth + mAnchorView.getWidth();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        vertOffset = -mAnchorView.getHeight() - Util.dpToPx(4);
        horizontalOffset = -mContentWidth+mAnchorView.getWidth()-Util.dpToPx(8);
    }
    mPopup.setVerticalOffset(vertOffset);
    mPopup.setHorizontalOffset(horizontalOffset);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}