Java Code Examples for com.github.jdsjlzx.recyclerview.LRecyclerView#setHasFixedSize()

The following examples show how to use com.github.jdsjlzx.recyclerview.LRecyclerView#setHasFixedSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListDragMenuActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //setLayoutManager must before setAdapter
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //init data
    ArrayList<ItemModel> dataList = new ArrayList<>();
    for (int i = 0; i < 16; i++) {
        ItemModel itemModel = new ItemModel();
        itemModel.title = "item" + i;
        dataList.add(itemModel);
    }

    mItemTouchHelper = new ItemTouchHelper(mCallback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    mDataAdapter = new DataAdapter(this);
    mDataAdapter.setDataList(dataList);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    mRecyclerView.addItemDecoration(divider);
    mRecyclerView.setHasFixedSize(true);


    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //add a FooterView
    mLRecyclerViewAdapter.addFooterView(new SampleFooter(this));

    //禁用下拉刷新功能
    mRecyclerView.setPullRefreshEnabled(false);

    //禁用自动加载更多功能
    mRecyclerView.setLoadMoreEnabled(false);

}
 
Example 2
Source File: Nest2RecyclerViewActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);
    mRecyclerView.setNestedScrollingEnabled(false);

    mShopAdapter = new ShopAdapterBase(this,mGoodsList);

    //setLayoutManager must before setAdapter
    GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(layoutManager);

    initData();

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mShopAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);
    mShopAdapter.addAll(mItemModels);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            MultipleItem item = mShopAdapter.getDataList().get(position);
            if (item.getItemType() == MultipleItem.LIST) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.refreshComplete(10);
                }
            },1000);
        }
    });

    mRecyclerView.refresh();

    //是否允许嵌套滑动
    mRecyclerView.setNestedScrollingEnabled(false);

}
 
Example 3
Source File: EndlessGridLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //setLayoutManager must before setAdapter
    GridLayoutManager manager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(manager);

    mDataAdapter = new DataAdapter(this);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    //设置头部加载颜色
    mRecyclerView.setHeaderViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载颜色
    mRecyclerView.setFooterViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载文字提示
    mRecyclerView.setFooterViewHint("拼命加载中","已经全部为你呈现了","网络不给力啊,点击再试一次吧");

    int spacing = getResources().getDimensionPixelSize(R.dimen.dp_4);
    mRecyclerView.addItemDecoration(SpacesItemDecoration.newInstance(spacing, spacing, manager.getSpanCount(), Color.GRAY));

    //根据需要选择使用GridItemDecoration还是SpacesItemDecoration
    GridItemDecoration divider = new GridItemDecoration.Builder(this)
            .setHorizontal(R.dimen.default_divider_padding)
            .setVertical(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    //mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setHasFixedSize(true);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //设置span,自己可以体验效果
    /*mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            if (position % 4 == 0) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });*/


    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });

    mRecyclerView.refresh();

}
 
Example 4
Source File: CollapsingToolbarLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collapsing_toolbar_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //init data
    ArrayList<ItemModel> dataList = new ArrayList<>();

    for (int i = 0; i < 10; i++) {

        ItemModel item = new ItemModel();
        item.id = i;
        item.title = "item" + i;
        dataList.add(item);
    }

    mCurrentCounter = dataList.size();

    mDataAdapter = new DataAdapter(this);
    mDataAdapter.addAll(dataList);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });

}