Search in sources :

Example 6 with LinearLayoutHelper

use of com.alibaba.android.vlayout.layout.LinearLayoutHelper in project vlayout by alibaba.

the class DebugActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
    VirtualLayoutManager virtualLayoutManager = new VirtualLayoutManager(this);
    DelegateAdapter delegateAdapter = new DelegateAdapter(virtualLayoutManager);
    List<Adapter> adapterList = new ArrayList<>();
    adapterList.add(new SubAdapter(new LinearLayoutHelper(20), 20));
    adapterList.add(new SubAdapter(new StickyLayoutHelper(true), 1));
    adapterList.add(new SubAdapter(new LinearLayoutHelper(20), 20));
    adapterList.add(new SubAdapter(new GridLayoutHelper(4), 80));
    // adapterList.add(new SubAdapter(new FixLayoutHelper(0, 0), 1));
    adapterList.add(new SubAdapter(new FixLayoutHelper(TOP_RIGHT, 0, 0), 1));
    delegateAdapter.addAdapters(adapterList);
    recyclerView.setLayoutManager(virtualLayoutManager);
    recyclerView.setAdapter(delegateAdapter);
}
Also used : DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) StickyLayoutHelper(com.alibaba.android.vlayout.layout.StickyLayoutHelper) ArrayList(java.util.ArrayList) FixLayoutHelper(com.alibaba.android.vlayout.layout.FixLayoutHelper) RecyclerView(android.support.v7.widget.RecyclerView) Adapter(com.alibaba.android.vlayout.DelegateAdapter.Adapter) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) GridLayoutHelper(com.alibaba.android.vlayout.layout.GridLayoutHelper)

Example 7 with LinearLayoutHelper

use of com.alibaba.android.vlayout.layout.LinearLayoutHelper in project vlayout by alibaba.

the class OnePlusNLayoutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });
    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText("Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    // layoutManager.setReverseLayout(true);
    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {

        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };
    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.setRecycledViewPool(viewPool);
    // recyclerView.addItemDecoration(itemDecoration);
    viewPool.setMaxRecycledViews(0, 20);
    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);
    recyclerView.setAdapter(delegateAdapter);
    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1)
                    return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this).inflate(R.layout.view_pager, parent, false));
                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {
            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;
                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(4f);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }
    if (HORIZONTAL_SCROLL_LAYOUT) {
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(3f);
        adapters.add(new SubAdapter(this, layoutHelper, 2));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(10, 10, 10, 10);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 3) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            // layoutParams.leftMargin = 10;
            // layoutParams.topMargin = 10;
            // layoutParams.rightMargin = 10;
            // layoutParams.bottomMargin = 10;
            // holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 4));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f });
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f });
        helper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 6));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f });
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xffed7612);
        // helper.setMargin(10, 10, 10, 10);
        // helper.setPadding(10, 10, 10, 10);
        helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f });
        adapters.add(new SubAdapter(this, helper, 7) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            // layoutParams.leftMargin = 10;
            // layoutParams.topMargin = 10;
            // layoutParams.rightMargin = 10;
            // layoutParams.bottomMargin = 10;
            // holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }
    if (SCROLL_FIX_LAYOUT) {
        ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20);
        layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);
        adapters.add(new SubAdapter(this, layoutHelper, 1) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(50, 50);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100));
    delegateAdapter.setAdapters(adapters);
    final Handler mainHandler = new Handler(Looper.getMainLooper());
    trigger = new Runnable() {

        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
        // mainHandler.postDelayed(trigger, 1000);
        }
    };
    mainHandler.postDelayed(trigger, 1000);
}
Also used : ScrollFixLayoutHelper(com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) GridLayoutHelper(com.alibaba.android.vlayout.layout.GridLayoutHelper) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) StickyLayoutHelper(com.alibaba.android.vlayout.layout.StickyLayoutHelper) OnePlusNLayoutHelperEx(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelperEx) EditText(android.widget.EditText) Rect(android.graphics.Rect) LayoutParams(com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams) LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) ViewGroup(android.view.ViewGroup) Handler(android.os.Handler) OnePlusNLayoutHelper(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) LinkedList(java.util.LinkedList) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager)

Example 8 with LinearLayoutHelper

use of com.alibaba.android.vlayout.layout.LinearLayoutHelper in project Tangram-Android by alibaba.

the class LinearCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    LinearLayoutHelper helper = null;
    if (oldHelper instanceof LinearLayoutHelper) {
        helper = (LinearLayoutHelper) oldHelper;
    } else {
        helper = new LinearLayoutHelper();
    }
    if (style != null) {
        helper.setBgColor(style.bgColor);
        if (!Float.isNaN(style.aspectRatio)) {
            helper.setAspectRatio(style.aspectRatio);
        }
        if (style.extras != null && style.extras.has(KEY_DIVIDE_HEIGHT)) {
            helper.setDividerHeight(Style.parseSize(style.extras.optString(KEY_DIVIDE_HEIGHT), 0));
        }
    }
    helper.setItemCount(mCells.size());
    helper.setMargin(style.margin[Style.MARGIN_LEFT_INDEX], style.margin[Style.MARGIN_TOP_INDEX], style.margin[Style.MARGIN_RIGHT_INDEX], style.margin[Style.MARGIN_BOTTOM_INDEX]);
    helper.setPadding(style.padding[Style.MARGIN_LEFT_INDEX], style.padding[Style.MARGIN_TOP_INDEX], style.padding[Style.MARGIN_RIGHT_INDEX], style.padding[Style.MARGIN_BOTTOM_INDEX]);
    return helper;
}
Also used : LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) Nullable(android.support.annotation.Nullable)

Example 9 with LinearLayoutHelper

use of com.alibaba.android.vlayout.layout.LinearLayoutHelper in project Tangram-Android by alibaba.

the class BannerCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(LayoutHelper oldHelper) {
    LinearLayoutHelper helper = new LinearLayoutHelper();
    helper.setItemCount(getCells().size());
    return helper;
}
Also used : LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) Nullable(android.support.annotation.Nullable)

Example 10 with LinearLayoutHelper

use of com.alibaba.android.vlayout.layout.LinearLayoutHelper in project Tangram-Android by alibaba.

the class VVCard method convertLayoutHelper.

@Nullable
@Override
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper oldHelper) {
    LinearLayoutHelper helper = new LinearLayoutHelper();
    helper.setItemCount(getCells().size());
    return helper;
}
Also used : LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) Nullable(android.support.annotation.Nullable)

Aggregations

LinearLayoutHelper (com.alibaba.android.vlayout.layout.LinearLayoutHelper)11 Nullable (android.support.annotation.Nullable)6 DelegateAdapter (com.alibaba.android.vlayout.DelegateAdapter)5 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)5 GridLayoutHelper (com.alibaba.android.vlayout.layout.GridLayoutHelper)5 RecyclerView (android.support.v7.widget.RecyclerView)4 StickyLayoutHelper (com.alibaba.android.vlayout.layout.StickyLayoutHelper)4 Rect (android.graphics.Rect)3 View (android.view.View)3 FixLayoutHelper (com.alibaba.android.vlayout.layout.FixLayoutHelper)3 OnePlusNLayoutHelper (com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper)3 ScrollFixLayoutHelper (com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper)3 LinkedList (java.util.LinkedList)3 Handler (android.os.Handler)2 ViewPager (android.support.v4.view.ViewPager)2 ViewGroup (android.view.ViewGroup)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 RecyclablePagerAdapter (com.alibaba.android.vlayout.RecyclablePagerAdapter)2 LayoutParams (com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams)2