Search in sources :

Example 31 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project UltimateRecyclerView by cymcsg.

the class HeaderPositionCalculator method itemIsObscuredByHeader.

/**
     * Determines if an item is obscured by a header
     *
     * @param parent
     * @param item        to determine if obscured by header
     * @param header      that might be obscuring the item
     * @param orientation of the {@link RecyclerView}
     * @return true if the item view is obscured by the header view
     */
private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) {
    RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams();
    Rect headerMargins = mDimensionCalculator.getMargins(header);
    int adapterPosition = parent.getChildAdapterPosition(item);
    if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) {
        // Handles an edge case where a trailing header is smaller than the current sticky header.
        return false;
    }
    if (orientation == LinearLayoutManager.VERTICAL) {
        int itemTop = item.getTop() - layoutParams.topMargin;
        int headerBottom = header.getBottom() + headerMargins.bottom + headerMargins.top;
        if (itemTop > headerBottom) {
            return false;
        }
    } else {
        int itemLeft = item.getLeft() - layoutParams.leftMargin;
        int headerRight = header.getRight() + headerMargins.right + headerMargins.left;
        if (itemLeft > headerRight) {
            return false;
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) RecyclerView(android.support.v7.widget.RecyclerView)

Example 32 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project Tusky by Vavassor.

the class ComposeActivity method addMediaToQueue.

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
             * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
             * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(), textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaButtons();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaButtons();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}
Also used : ImageView(android.widget.ImageView) AppCompatResources(android.support.v7.content.res.AppCompatResources) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 33 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project EasyRecyclerView by Jude95.

the class RecyclerArrayAdapter method createSpViewByType.

private View createSpViewByType(ViewGroup parent, int viewType) {
    for (ItemView headerView : headers) {
        if (headerView.hashCode() == viewType) {
            View view = headerView.onCreateView(parent);
            StaggeredGridLayoutManager.LayoutParams layoutParams;
            if (view.getLayoutParams() != null)
                layoutParams = new StaggeredGridLayoutManager.LayoutParams(view.getLayoutParams());
            else
                layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.setFullSpan(true);
            view.setLayoutParams(layoutParams);
            return view;
        }
    }
    for (ItemView footerview : footers) {
        if (footerview.hashCode() == viewType) {
            View view = footerview.onCreateView(parent);
            StaggeredGridLayoutManager.LayoutParams layoutParams;
            if (view.getLayoutParams() != null)
                layoutParams = new StaggeredGridLayoutManager.LayoutParams(view.getLayoutParams());
            else
                layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.setFullSpan(true);
            view.setLayoutParams(layoutParams);
            return view;
        }
    }
    return null;
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) EasyRecyclerView(com.jude.easyrecyclerview.EasyRecyclerView) View(android.view.View)

Example 34 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project BaseRecyclerViewAdapterHelper by CymChad.

the class BaseQuickAdapter method addHeaderView.

/**
     * @param header
     * @param index
     * @param orientation
     */
public int addHeaderView(View header, int index, int orientation) {
    if (mHeaderLayout == null) {
        mHeaderLayout = new LinearLayout(header.getContext());
        if (orientation == LinearLayout.VERTICAL) {
            mHeaderLayout.setOrientation(LinearLayout.VERTICAL);
            mHeaderLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
        } else {
            mHeaderLayout.setOrientation(LinearLayout.HORIZONTAL);
            mHeaderLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
        }
    }
    final int childCount = mHeaderLayout.getChildCount();
    if (index < 0 || index > childCount) {
        index = childCount;
    }
    mHeaderLayout.addView(header, index);
    if (mHeaderLayout.getChildCount() == 1) {
        int position = getHeaderViewPosition();
        if (position != -1) {
            notifyItemInserted(position);
        }
    }
    return index;
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) LinearLayout(android.widget.LinearLayout)

Example 35 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project BaseRecyclerViewAdapterHelper by CymChad.

the class BaseQuickAdapter method setEmptyView.

public void setEmptyView(View emptyView) {
    boolean insert = false;
    if (mEmptyLayout == null) {
        mEmptyLayout = new FrameLayout(emptyView.getContext());
        final LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        final ViewGroup.LayoutParams lp = emptyView.getLayoutParams();
        if (lp != null) {
            layoutParams.width = lp.width;
            layoutParams.height = lp.height;
        }
        mEmptyLayout.setLayoutParams(layoutParams);
        insert = true;
    }
    mEmptyLayout.removeAllViews();
    mEmptyLayout.addView(emptyView);
    mIsUseEmpty = true;
    if (insert) {
        if (getEmptyViewCount() == 1) {
            int position = 0;
            if (mHeadAndEmptyEnable && getHeaderLayoutCount() != 0) {
                position++;
            }
            notifyItemInserted(position);
        }
    }
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout)

Aggregations

View (android.view.View)86 RecyclerView (android.support.v7.widget.RecyclerView)78 TextView (android.widget.TextView)24 ViewGroup (android.view.ViewGroup)23 ImageView (android.widget.ImageView)20 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)13 FrameLayout (android.widget.FrameLayout)10 Toolbar (android.support.v7.widget.Toolbar)9 Rect (android.graphics.Rect)8 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)8 LinearLayout (android.widget.LinearLayout)8 BindView (butterknife.BindView)8 ActionMenuView (android.support.v7.widget.ActionMenuView)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 EditText (android.widget.EditText)6 CollapsibleActionView (android.support.v7.view.CollapsibleActionView)5 MenuView (android.support.v7.view.menu.MenuView)5 ImageView (carbon.widget.ImageView)5 TextView (carbon.widget.TextView)5