Android Studio之RecyclerView和CardView初体验

RecyclerView : 只负责View的复用和回收,其余事情交由ViewHolder来处理,在XML中的用法和Listview差很少
android

               --------------------------------------    RecyclerView   --------------------------------------布局

  1. 必须为其设置一个LayoutManager:动画

recycler_view.setLayoutManager(new GridLayoutManager(this, 2));
recycler_view.setLayoutManager(new LinearLayoutManager(this));
recycler_view.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));

  2.  支持普通listview  gridview  ,支持横竖方向的设置,而且当设置item高度为随机数时能够直接变成瀑布流效果this

    设置动画效果:
spa

recycler_view.setItemAnimator(new DefaultItemAnimator());

  3.  adapter必须继承自RecyclerView.Adapter<HomeAdapter.MyHolder>code

    删除某个item时候的Notify方法为:xml

notifyItemRemoved(position);

    




              --------------------------------------    CardView  --------------------------------------  继承

    1.CardView是一个ViewGroup,用法与RelativeLayout等布局差很少get

    2.须要自定义一个命名空间    it

android.support.v7.widget.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"

    3.提供了几个自定义属性:

cardBackgroundColor
cardCornerRadius

cardElevation
相关文章
相关标签/搜索