RecyclerView

来源:互联网 发布:比特币交易平台 知乎 编辑:程序博客网 时间:2024/04/26 18:54

listview:

recyclerView.setLayoutManager(new LinearLayoutManager(FirstActivity.this,LinearLayoutManager.VERTICAL,false));

gridview:

recyclerView.setLayoutManager(new GridLayoutManager(FirstActivity.this,3));
horizontal(横向):

recyclerView.setLayoutManager(new LinearLayoutManager(FirstActivity.this,LinearLayoutManager.HORIZONTAL,false));

horizontal(横向多行):

recyclerView.setLayoutManager(new GridLayoutManager(FirstActivity.this,3, OrientationHelper.HORIZONTAL,false));

瀑布流:

recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL));

adapter.notifyItemInserted(5);//添加效果

adapter.notifyItemRemoved(5);//删除效果


//给recyclerView设置增删的动画....默认使用动画的
//new DefaultItemAnimator()这个是默认的动画,,,设置与不设置都会有
//recyclerView只给我们提供了这一种默认的动画,,,,,https://github.com/gabrielemariotti/RecyclerViewItemAnimators
recyclerView.setItemAnimator(new DefaultItemAnimator());


//添加分割线....new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)默认的类似黑色的分割线
//可以使用shape画出一条分割线....然后使用自己的分割线(自己试)
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
dividerItemDecoration.setDrawable(getResources().getDrawable(R.mipmap.ic_launcher));
recyclerView.addItemDecoration(dividerItemDecoration);