RecyclerView : 只負責View的複用和回收,其餘事情交由ViewHolder來處理,在XML中的用法和Listview差很少
android
-------------------------------------- RecyclerView --------------------------------------佈局
必須爲其設置一個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