Android Studio之RecyclerView和CardView初體驗

來源:互聯網
上載者:User

標籤:

RecyclerView : 只負責View的複用和回收,其他事情交由ViewHolder來處理,在XML中的用法和Listview差不多

               --------------------------------------    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高度為隨機數時可以直接變成瀑布流效果

    設定動畫效果:

recycler_view.setItemAnimator(new DefaultItemAnimator());

  3.  adapter必須繼承自RecyclerView.Adapter<HomeAdapter.MyHolder>

    刪除某個item時候的Notify方法為:

notifyItemRemoved(position);

    




              --------------------------------------    CardView  --------------------------------------  

    1.CardView是一個ViewGroup,用法與RelativeLayout等布局差不多

    2.需要自訂一個命名空間    

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

    3.提供了幾個自訂屬性:

cardBackgroundColor
cardCornerRadius

cardElevation


Android Studio之RecyclerView和CardView初體驗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.