Search in sources :

Example 6 with HORIZONTAL

use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project vlayout by alibaba.

the class OnePlusNLayoutHelperEx method layoutViews.

@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
    // reach the end of this layout
    final int originCurPos = layoutState.getCurrentPosition();
    if (isOutOfRange(originCurPos)) {
        return;
    }
    if (mChildrenViews == null || mChildrenViews.length != getItemCount()) {
        mChildrenViews = new View[getItemCount()];
    }
    int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
    if (count != getItemCount()) {
        Log.w(TAG, "The real number of children is not match with range of LayoutHelper");
    }
    final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
    final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
    final int parentWidth = helper.getContentWidth();
    final int parentHeight = helper.getContentHeight();
    final int parentHPadding = helper.getPaddingLeft() + helper.getPaddingRight() + getHorizontalMargin() + getHorizontalPadding();
    final int parentVPadding = helper.getPaddingTop() + helper.getPaddingBottom() + getVerticalMargin() + getVerticalPadding();
    int mainConsumed = 0;
    if (count == 5) {
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        if (layoutInVertical) {
            lp2.topMargin = lp1.topMargin;
            lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
            lp3.leftMargin = lp2.leftMargin;
            lp4.rightMargin = lp2.rightMargin;
            lp5.rightMargin = lp3.rightMargin;
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5f);
            int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            int height3 = (height1 - lp2.bottomMargin - lp3.topMargin) - height2;
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            mainConsumed = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, height2 + lp2.topMargin + lp2.bottomMargin + Math.max(height3 + lp3.topMargin + lp3.bottomMargin, height3 + lp4.topMargin + lp4.bottomMargin)) + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
            int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right4, mAreaRect.bottom, helper);
            layoutChild(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right4 + orientationHelper.getDecoratedMeasurementInOther(child5), mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5);
    } else if (count == 6) {
        // added at 2017/3/7 can extract method
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[5] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final View child6 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[5];
        final VirtualLayoutManager.LayoutParams lp6 = new VirtualLayoutManager.LayoutParams(child6.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        final float weight6 = getViewMainWeight(lp1, 5);
        if (layoutInVertical) {
            lp2.topMargin = lp1.topMargin;
            lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
            lp3.leftMargin = lp2.leftMargin;
            lp4.rightMargin = lp2.rightMargin;
            lp5.rightMargin = lp2.rightMargin;
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? availableSpace - width1 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5);
            int bottomavailableSpace = parentWidth - parentHPadding - lp4.leftMargin - lp4.rightMargin - lp5.leftMargin - lp5.rightMargin - lp6.leftMargin - lp6.rightMargin;
            int width4 = Float.isNaN(weight4) ? (int) (bottomavailableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width4 : (int) (availableSpace * weight5 / 100 + 0.5f);
            int width6 = Float.isNaN(weight6) ? width4 : (int) (availableSpace * weight6 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            int height3 = (height1 - lp2.bottomMargin - lp3.topMargin) - height2;
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child6, MeasureSpec.makeMeasureSpec(width6 + lp6.leftMargin + lp6.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp6.topMargin + lp6.bottomMargin, MeasureSpec.EXACTLY));
            int maxTopHeight = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, (height2 + lp2.topMargin + lp2.bottomMargin) * 2);
            int maxBottomHeight = Math.max(height3 + lp4.topMargin + lp4.bottomMargin, Math.max(height3 + lp5.topMargin + lp5.bottomMargin, height3 + lp6.topMargin + lp6.bottomMargin));
            mainConsumed = maxTopHeight + maxBottomHeight + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right1 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right1, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), right3, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), helper);
            int right4 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, mAreaRect.left, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right4, mAreaRect.bottom, helper);
            int right5 = right4 + orientationHelper.getDecoratedMeasurementInOther(child5);
            layoutChild(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right5, mAreaRect.bottom, helper);
            int right6 = right5 + orientationHelper.getDecoratedMeasurementInOther(child6);
            layoutChild(child6, right5, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), right6, mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5, child6);
    } else if (count == 7) {
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[6] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[5] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final View child6 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[5];
        final VirtualLayoutManager.LayoutParams lp6 = new VirtualLayoutManager.LayoutParams(child6.getLayoutParams());
        final View child7 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[6];
        final VirtualLayoutManager.LayoutParams lp7 = new VirtualLayoutManager.LayoutParams(child7.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        final float weight6 = getViewMainWeight(lp1, 5);
        final float weight7 = getViewMainWeight(lp1, 6);
        if (layoutInVertical) {
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5);
            int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
            int width6 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight6 / 100 + 0.5f);
            int width7 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight7 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 3.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child6, MeasureSpec.makeMeasureSpec(width6 + lp6.leftMargin + lp6.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp6.topMargin + lp6.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child7, MeasureSpec.makeMeasureSpec(width7 + lp7.leftMargin + lp7.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp7.topMargin + lp7.bottomMargin, MeasureSpec.EXACTLY));
            int maxRightHeight = Math.max(height2 + lp2.topMargin + lp2.bottomMargin, height2 + lp3.topMargin + lp3.bottomMargin) + Math.max(height2 + lp4.topMargin + lp4.bottomMargin, height2 + lp5.topMargin + lp5.bottomMargin) + Math.max(height2 + lp6.topMargin + lp6.bottomMargin, height2 + lp7.topMargin + lp7.bottomMargin);
            int maxHeight = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, maxRightHeight);
            mainConsumed = maxHeight + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
            int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, right1, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), helper);
            int right5 = right4 + orientationHelper.getDecoratedMeasurementInOther(child5);
            layoutChild(child5, right4, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right5, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), helper);
            int right6 = right1 + orientationHelper.getDecoratedMeasurementInOther(child6);
            layoutChild(child6, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), right6, mAreaRect.bottom, helper);
            layoutChild(child7, right6, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), right6 + orientationHelper.getDecoratedMeasurementInOther(child7), mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5, child6);
    }
    result.mConsumed = mainConsumed;
    Arrays.fill(mChildrenViews, null);
}
Also used : OrientationHelper(android.support.v7.widget.OrientationHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 7 with HORIZONTAL

use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project TrekAdvisor by peterLaurence.

the class TracksManageFragment method generateTracks.

private void generateTracks(Map map) {
    Context ctx = getContext();
    RecyclerView recyclerView = new RecyclerView(ctx);
    recyclerView.setHasFixedSize(false);
    /* All cards are laid out vertically */
    LinearLayoutManager llm = new LinearLayoutManager(ctx);
    recyclerView.setLayoutManager(llm);
    /* Apply item decoration (add an horizontal divider) */
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(ctx, DividerItemDecoration.VERTICAL);
    Drawable divider = this.getContext().getDrawable(R.drawable.divider);
    if (divider != null) {
        dividerItemDecoration.setDrawable(divider);
    }
    recyclerView.addItemDecoration(dividerItemDecoration);
    mTrackAdapter = new TrackAdapter(map, this, ctx.getColor(R.color.colorAccent), ctx.getColor(R.color.colorPrimaryTextWhite), ctx.getColor(R.color.colorPrimaryTextBlack));
    recyclerView.setAdapter(mTrackAdapter);
    /* Swipe to dismiss functionality */
    ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            /* Remove the track from the list and from the map */
            mTrackAdapter.removeItem(viewHolder.getAdapterPosition());
            /* Update the view */
            if (mTrackChangeListener != null) {
                mTrackChangeListener.onTrackVisibilityChanged();
            }
            /* Save */
            saveChanges();
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    rootView.addView(recyclerView, 0);
}
Also used : Context(android.content.Context) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Drawable(android.graphics.drawable.Drawable) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration)

Example 8 with HORIZONTAL

use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project Tangram-Android by alibaba.

the class LinearScrollView method init.

private void init() {
    setGravity(Gravity.CENTER_HORIZONTAL);
    setOrientation(VERTICAL);
    inflate(getContext(), R.layout.tangram_linearscrollview, this);
    setClickable(true);
    recyclerView = (RecyclerView) findViewById(R.id.tangram_linearscrollview_container);
    indicator = findViewById(R.id.tangram_linearscrollview_indicator);
    indicatorContainer = findViewById(R.id.tangram_linearscrollview_indicator_container);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    layoutManager.setOrientation(HORIZONTAL);
    recyclerView.setLayoutManager(layoutManager);
    totalDistanceOfIndicator = Style.dp2px(34);
    touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    overScrollDecorator = new HorizontalOverScrollBounceEffectDecoratorExt(new StaticOverScrollDecorAdapter(this));
}
Also used : HorizontalOverScrollBounceEffectDecoratorExt(com.tmall.wireless.tangram.ext.HorizontalOverScrollBounceEffectDecoratorExt) StaticOverScrollDecorAdapter(me.everything.android.ui.overscroll.adapters.StaticOverScrollDecorAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 9 with HORIZONTAL

use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project instructure-android by instructure.

the class DividerDecoration method onDrawOver.

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mDivider == null) {
        super.onDrawOver(c, parent, state);
        return;
    }
    // Initialization needed to avoid compiler warning
    int left = 0, right = 0, top = 0, bottom = 0, size;
    int orientation = getOrientation(parent);
    int childCount = parent.getChildCount();
    if (orientation == LinearLayoutManager.VERTICAL) {
        size = mDivider.getIntrinsicHeight();
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
    } else {
        // horizontal
        size = mDivider.getIntrinsicWidth();
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
    }
    for (int i = 1; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        if (orientation == LinearLayoutManager.VERTICAL) {
            top = child.getTop() - params.topMargin;
            bottom = top + size;
        } else {
            // horizontal
            left = child.getLeft() - params.leftMargin;
            right = left + size;
        }
        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 10 with HORIZONTAL

use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project android-advancedrecyclerview by h6ah4i.

the class ItemSlidingAnimator method animateSlideInternal.

private boolean animateSlideInternal(RecyclerView.ViewHolder holder, boolean horizontal, int translationX, int translationY, long duration, Interpolator interpolator, SwipeFinishInfo swipeFinish) {
    if (!(holder instanceof SwipeableItemViewHolder)) {
        return false;
    }
    final View containerView = SwipeableViewHolderUtils.getSwipeableContainerView(holder);
    final int prevTranslationX = (int) (containerView.getTranslationX() + 0.5f);
    final int prevTranslationY = (int) (containerView.getTranslationY() + 0.5f);
    endAnimation(holder);
    final int curTranslationX = (int) (containerView.getTranslationX() + 0.5f);
    final int curTranslationY = (int) (containerView.getTranslationY() + 0.5f);
    // noinspection UnnecessaryLocalVariable
    final int toX = translationX;
    // noinspection UnnecessaryLocalVariable
    final int toY = translationY;
    if ((duration == 0) || (curTranslationX == toX && curTranslationY == toY) || (Math.max(Math.abs(toX - prevTranslationX), Math.abs(toY - prevTranslationY)) <= mImmediatelySetTranslationThreshold)) {
        containerView.setTranslationX(toX);
        containerView.setTranslationY(toY);
        return false;
    }
    containerView.setTranslationX(prevTranslationX);
    containerView.setTranslationY(prevTranslationY);
    SlidingAnimatorListenerObject listener = new SlidingAnimatorListenerObject(mAdapter, mActive, holder, toX, toY, duration, horizontal, interpolator, swipeFinish);
    listener.start();
    return true;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)33 View (android.view.View)31 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)6 TextView (android.widget.TextView)5 ImageView (android.widget.ImageView)4 Context (android.content.Context)3 ViewGroup (android.view.ViewGroup)3 LayoutParams (com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams)3 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1