Search in sources :

Example 46 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project AndroidLife by CaMnter.

the class DividerItemDecoration method drawHorizontal.

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 47 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project Tangram-Android by alibaba.

the class LinearScrollView method postBindView.

@Override
public void postBindView(BaseCell cell) {
    if (lSCell == null) {
        return;
    }
    recyclerView.setRecycledViewPool(lSCell.getRecycledViewPool());
    recyclerView.removeItemDecoration(itemDecoration);
    if (lSCell.hGap > 0) {
        itemDecoration = new RecyclerView.ItemDecoration() {

            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                outRect.set(0, 0, 0, 0);
                int cellCount = lSCell.cells.size();
                int viewIndex = (int) view.getTag(R.id.TANGRAM_LINEAR_SCROLL_POS);
                int rowCount = (int) (lSCell.cells.size() * 1.0f / lSCell.maxRows + 0.5f);
                boolean isLastCellInRow = false;
                if ((viewIndex + 1) % rowCount == 0) {
                    // the last cell in every row
                    isLastCellInRow = true;
                }
                if (viewIndex == (cellCount - 1)) {
                    // the last cell in cells
                    isLastCellInRow = true;
                }
                if (viewIndex % rowCount == 0) {
                    // first view only set right
                    outRect.right = (int) (lSCell.hGap / 2);
                } else if (isLastCellInRow) {
                    // last view only set left
                    outRect.left = (int) (lSCell.hGap / 2);
                    if (lSCell.maxRows > 1 && (cellCount % lSCell.maxRows == 1) && (viewIndex == cellCount - 1)) {
                        // the last cell in penultimate row
                        outRect.right = (int) (lSCell.hGap / 2);
                    }
                } else {
                    outRect.left = (int) (lSCell.hGap / 2);
                    outRect.right = (int) (lSCell.hGap / 2);
                }
            }
        };
        recyclerView.addItemDecoration(itemDecoration);
    }
    float[] starts = null;
    if (lSCell.cells != null && lSCell.cells.size() > 0) {
        int maxRowCount = lSCell.cells.size();
        if (lSCell.maxRows > 1) {
            maxRowCount = (int) (maxRowCount * 1.0f / lSCell.maxRows + 0.5f);
        }
        starts = new float[maxRowCount];
        for (int i = 0; i < maxRowCount; i++) {
            int rowIndex = lSCell.maxRows * i;
            int mapperIndex = lSCell.getMapperPosition(rowIndex);
            starts[i] = totalDistance;
            BaseCell bc = lSCell.cells.get(mapperIndex);
            if (bc.style != null && bc.style.margin.length > 0) {
                totalDistance = totalDistance + bc.style.margin[1] + bc.style.margin[3];
            }
            if (!Double.isNaN(lSCell.pageWidth)) {
                if (bc.extras.has("pageWidth")) {
                    totalDistance += Style.parseSize(bc.extras.optString("pageWidth"), 0);
                } else {
                    totalDistance += lSCell.pageWidth;
                }
            }
            if (i > 0 && lSCell.hGap > 0) {
                totalDistance += lSCell.hGap;
            }
        }
    }
    totalDistance -= getScreenWidth();
    // calculate height of recycler view.
    ViewGroup.LayoutParams lp = recyclerView.getLayoutParams();
    if (!Double.isNaN(lSCell.pageHeight)) {
        if (lSCell.maxRows == 0) {
            lp.height = (int) (lSCell.pageHeight + 0.5f);
        } else {
            lp.height = (int) (lSCell.pageHeight * lSCell.maxRows + 0.5f);
        }
        if (lSCell.maxRows > 1 && lSCell.vGap > 0) {
            lp.height += (int) ((lSCell.maxRows - 1) * lSCell.vGap + 0.5f);
        }
    }
    recyclerView.setLayoutParams(lp);
    recyclerView.setAdapter(lSCell.adapter);
    if (lSCell.hasIndicator && totalDistance > 0) {
        setViewColor(indicator, lSCell.indicatorColor);
        setViewColor(indicatorContainer, lSCell.defaultIndicatorColor);
        setIndicatorMeasure(indicator, (int) Math.round(lSCell.indicatorWidth), (int) Math.round(lSCell.indicatorHeight), 0);
        setIndicatorMeasure(indicatorContainer, (int) Math.round(lSCell.defaultIndicatorWidth), (int) Math.round(lSCell.indicatorHeight), (int) Math.round(lSCell.indicatorMargin));
        indicatorContainer.setVisibility(VISIBLE);
    } else {
        indicatorContainer.setVisibility(GONE);
    }
    recyclerView.addOnScrollListener(onScrollListener);
    setBackgroundColor(lSCell.bgColor);
    if (lSCell.retainScrollState && starts != null) {
        GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
        int position = computeFirstCompletelyVisibleItemPositionForScrolledX(starts);
        lm.scrollToPositionWithOffset(position * lSCell.maxRows, (int) (starts[position] - lSCell.currentDistance));
    }
    if (lSCell.scrollMarginLeft > 0 || lSCell.scrollMarginRight > 0) {
        setPadding(lSCell.scrollMarginLeft, 0, lSCell.scrollMarginRight, 0);
        setClipToPadding(false);
        setClipChildren(false);
    } else {
        setPadding(0, 0, 0, 0);
        setClipToPadding(true);
        setClipChildren(true);
    }
    recycleView(lSCell);
    bindHeaderView(lSCell.mHeader);
    bindFooterView(lSCell.mFooter);
}
Also used : Rect(android.graphics.Rect) GridLayoutManager(android.support.v7.widget.GridLayoutManager) BaseCell(com.tmall.wireless.tangram.structure.BaseCell) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 48 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project Tangram-Android by alibaba.

the class BannerView method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int measureWidth = mUltraViewPager.getMeasuredWidth();
    int measureHeight = mUltraViewPager.getMeasuredHeight();
    int indicatorHeight = mIndicator.getMeasuredHeight();
    int top = getPaddingTop();
    int left = getPaddingLeft();
    if (!mHeaderViewHolders.isEmpty()) {
        for (int i = 0, count = mHeaderViewHolders.size(); i < count; i++) {
            View header = mHeaderViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) header.getLayoutParams();
            header.layout(left + lp.leftMargin, top + lp.topMargin, header.getMeasuredWidth(), top + lp.topMargin + header.getMeasuredHeight());
            top += lp.topMargin + header.getMeasuredHeight() + lp.bottomMargin;
        }
    }
    mUltraViewPager.layout(left, top, measureWidth, top + measureHeight);
    top += measureHeight;
    if (isIndicatorOutside) {
        mIndicator.layout(left, top, measureWidth, top + measureHeight + indicatorHeight);
        top += indicatorHeight;
    } else {
        mIndicator.layout(left, top - indicatorHeight, measureWidth, top);
    }
    if (!mFooterViewHolders.isEmpty()) {
        for (int i = 0, count = mFooterViewHolders.size(); i < count; i++) {
            View footer = mFooterViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) footer.getLayoutParams();
            footer.layout(left + lp.leftMargin, top + lp.topMargin, footer.getMeasuredWidth(), top + lp.topMargin + footer.getMeasuredHeight());
            top += +lp.topMargin + footer.getMeasuredHeight() + lp.bottomMargin;
        }
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 49 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project Tangram-Android by alibaba.

the class BannerView method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int measureWidth = mUltraViewPager.getMeasuredWidth();
    int measureHeight = mUltraViewPager.getMeasuredHeight();
    int indicatorHeight = mIndicator.getMeasuredHeight();
    int top = getPaddingTop();
    int left = getPaddingLeft();
    if (!mHeaderViewHolders.isEmpty()) {
        for (int i = 0, count = mHeaderViewHolders.size(); i < count; i++) {
            View header = mHeaderViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) header.getLayoutParams();
            header.layout(left + lp.leftMargin, top + lp.topMargin, header.getMeasuredWidth(), top + lp.topMargin + header.getMeasuredHeight());
            top += lp.topMargin + header.getMeasuredHeight() + lp.bottomMargin;
        }
    }
    mUltraViewPager.layout(left, top, measureWidth, top + measureHeight);
    top += measureHeight;
    if (isIndicatorOutside) {
        mIndicator.layout(left, top, measureWidth, top + measureHeight + indicatorHeight);
        top += indicatorHeight;
    } else {
        mIndicator.layout(left, top - indicatorHeight, measureWidth, top);
    }
    if (!mFooterViewHolders.isEmpty()) {
        for (int i = 0, count = mFooterViewHolders.size(); i < count; i++) {
            View footer = mFooterViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) footer.getLayoutParams();
            footer.layout(left + lp.leftMargin, top + lp.topMargin, footer.getMeasuredWidth(), top + lp.topMargin + footer.getMeasuredHeight());
            top += +lp.topMargin + footer.getMeasuredHeight() + lp.bottomMargin;
        }
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 50 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project NeuCardReader by liuyanyi.

the class ItemDivider method drawHorizontal.

/**
 * 绘制间隔
 */
private void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)291 RecyclerView (android.support.v7.widget.RecyclerView)276 Paint (android.graphics.Paint)43 TextView (android.widget.TextView)36 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 ImageView (android.widget.ImageView)20 Rect (android.graphics.Rect)11 Intent (android.content.Intent)9 SuppressLint (android.annotation.SuppressLint)8 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)8 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)8 ArrayList (java.util.ArrayList)8 AlertDialog (android.support.v7.app.AlertDialog)7 Toolbar (android.support.v7.widget.Toolbar)7 ViewGroup (android.view.ViewGroup)7 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 Button (android.widget.Button)6 Animator (android.animation.Animator)5 TargetApi (android.annotation.TargetApi)5 Activity (android.app.Activity)5