Java Code Examples for android.support.v7.widget.StaggeredGridLayoutManager#setGapStrategy()
The following examples show how to use
android.support.v7.widget.StaggeredGridLayoutManager#setGapStrategy() .
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: EndlessStaggeredGridLayoutActivity.java From LRecyclerView with Apache License 2.0 | 4 votes |
@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); mDataAdapter = new DataAdapter(this); mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter); mRecyclerView.setAdapter(mLRecyclerViewAdapter); //setLayoutManager StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( 2, StaggeredGridLayoutManager.VERTICAL); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); //防止item位置互换 layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); mRecyclerView.setLayoutManager(layoutManager); mLRecyclerViewAdapter.addHeaderView(new SampleHeader(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); } } }); mRecyclerView.refresh(); }
Example 2
Source File: GirlItemFragment.java From NiceRead with Apache License 2.0 | 4 votes |
@Override protected void initView() { EventBus.getDefault().register(this); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent, R.color.colorPrimaryDark); mSwipeRefreshLayout.setOnRefreshListener(this); //实现首次自动显示加载提示 mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); mGirlItemAdapter = new GirlItemAdapter(mActivity, new ArrayList<GirlItemData>(), true); mGirlItemAdapter.setLoadingView(R.layout.load_loading_layout); mGirlItemAdapter.setOnItemClickListener(new OnItemClickListeners<GirlItemData>() { @Override public void onItemClick(ViewHolder viewHolder, GirlItemData girlItemData, int position) { Intent intent = new Intent(mActivity, GirlDetailActivity.class); intent.putExtra("girl_item_data", girlItemData); startActivity(intent); } }); mGirlItemAdapter.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore(boolean isReload) { if (PAGE_COUNT == mTempPageCount && !isReload) { return; } isLoadMore = true; PAGE_COUNT = mTempPageCount; fetchData(); } }); final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);//可防止Item切换 mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mGirlItemAdapter); }