import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class VlayoutDelegateAdapterActivity extends Activity{
private RecyclerView recyclerView;
private VlayoutDelegateAdapterAdapter vlayoutAdapter;
private List<String> datas;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vlayout_layout);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
datas = new ArrayList<>();
for (int i = 0; i < 100; i++) {
datas.add("VlayoutActivity"+i);
}
//绑定VirtualLayoutManager
VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
LinearLayoutHelper linearLayoutHelper = new LinearLayoutHelper();
linearLayoutHelper.setItemCount(5);
linearLayoutHelper.setMarginBottom(20);
GridLayoutHelper gridLayoutHelper1 = new GridLayoutHelper(3);
gridLayoutHelper1.setItemCount(11);
gridLayoutHelper1.setMarginBottom(20);
gridLayoutHelper1.setAutoExpand(false);
GridLayoutHelper gridLayoutHelper2 = new GridLayoutHelper(5);
gridLayoutHelper2.setItemCount(10);
gridLayoutHelper2.setAutoExpand(false);
gridLayoutHelper2.setMarginBottom(20);
List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
adapters.add(new VlayoutDelegateAdapterAdapter(this,linearLayoutHelper,5, datas){
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
}
});
adapters.add(new VlayoutDelegateAdapterAdapter(this,gridLayoutHelper1,11, datas){
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
}
});
adapters.add(new VlayoutDelegateAdapterAdapter(this,gridLayoutHelper2,10, datas){
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
}
});
//绑定delegateAdapter
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager);
delegateAdapter.setAdapters(adapters);
recyclerView.setAdapter(delegateAdapter);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.layout.FixAreaLayoutHelper;
import com.alibaba.android.vlayout.layout.FixLayoutHelper;
import com.alibaba.android.vlayout.layout.FloatLayoutHelper;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class VlayoutVirtualAdapterActivity extends Activity{
private RecyclerView recyclerView;
private VlayoutDelegateAdapterAdapter vlayoutAdapter;
private List<String> datas;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vlayout_layout);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
datas = new ArrayList<>();
for (int i = 0; i < 100; i++) {
datas.add("VlayoutActivity"+i);
}
//绑定VirtualLayoutManager
VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
LinearLayoutHelper linearLayoutHelper = new LinearLayoutHelper();
linearLayoutHelper.setItemCount(5);
linearLayoutHelper.setMarginBottom(20);
GridLayoutHelper gridLayoutHelper1 = new GridLayoutHelper(3);
gridLayoutHelper1.setItemCount(11);
gridLayoutHelper1.setMarginBottom(20);
gridLayoutHelper1.setAutoExpand(false);
GridLayoutHelper gridLayoutHelper2 = new GridLayoutHelper(5);
gridLayoutHelper2.setItemCount(10);
gridLayoutHelper2.setAutoExpand(false);
gridLayoutHelper2.setMarginBottom(20);
FixAreaLayoutHelper fixAreaLayoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_LEFT,10,10);
fixAreaLayoutHelper.setItemCount(1);
FloatLayoutHelper floatLayoutHelper = new FloatLayoutHelper();
floatLayoutHelper.setItemCount(1);
floatLayoutHelper.setMarginBottom(100);
ScrollFixLayoutHelper scrollFixLayoutHelper = new ScrollFixLayoutHelper(ScrollFixLayoutHelper.SHOW_ON_ENTER, 100, 100);
scrollFixLayoutHelper.setItemCount(1);
List<LayoutHelper> helpers = new LinkedList<>();
helpers.add(gridLayoutHelper1);
helpers.add(linearLayoutHelper);
helpers.add(gridLayoutHelper2);
helpers.add(fixAreaLayoutHelper);
helpers.add(floatLayoutHelper);
helpers.add(scrollFixLayoutHelper);
// helpers.add(columnLayoutHelper);
// helpers.add(singleLayoutHelper);
// helpers.add(onePlusNLayoutHelper);
// helpers.add(staggeredGridLayoutHelper);
layoutManager.setLayoutHelpers(helpers);
recyclerView.setAdapter(new VlayoutVirtualAdapterAdapter(this, layoutManager, datas, 29));
}
}
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import java.util.List;
public class VlayoutVirtualAdapterAdapter extends VirtualLayoutAdapter<VlayoutVirtualAdapterAdapter.MainViewHolder> {
private Context context;
private LayoutHelper layoutHelper;
private RecyclerView.LayoutParams layoutParams;
private int count = 0;
private List<String> datas;
public VlayoutVirtualAdapterAdapter(Context context, VirtualLayoutManager virtualLayoutManager, List<String> datas, int count) {
super(virtualLayoutManager);
this.context = context;
this.datas = datas;
this.count = count;
}
@Override
public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new MainViewHolder(LayoutInflater.from(context).inflate(R.layout.vlayout_layout_cell,parent,false));
}
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
holder.tv1.setText(datas.get(position));
if (position == 25) {
holder.itemView.setBackgroundColor(0xccff22ff);
}else if (position == 26) {
holder.itemView.setBackgroundColor(0xaa22ff22);
}else if (position == 27) {
holder.itemView.setBackgroundColor(0xccff22ff);
}else {
if (position % 2 == 0) {
holder.itemView.setBackgroundColor(0xffBF2BFF);
} else {
holder.itemView.setBackgroundColor(0xffE8FF1E);
}
}
}
@Override
public int getItemCount() {
return count;
}
static class MainViewHolder extends RecyclerView.ViewHolder {
public TextView tv1;
public MainViewHolder(View itemView) {
super(itemView);
tv1 = (TextView) itemView.findViewById(R.id.text);
}
}
}