Use of Recyclerview, CardView, palette in Android L

Source: Internet
Author: User

    1. Recyclerview
    2. CardView
    3. Palette

"Material Design" mentioned, the Android L version added Recyclerview, CardView, Palette. Recyclerview, CardView are new widgets for displaying complex views. Palette, as a palette class, lets you extract prominent colors from an image.


Recyclerview

Recyclerview is used as an alternative to the ListView, Recyclerview standardizes the Viewholder, Convertview in theListView is multiplexed, in Recyclerview, is to put Viewholder as the unit of the cache, and then Convertview as the Viewholder member variable remains in the Viewholder, that is, assuming that no screen shows 10 entries, then create 10 Viewholder cache. Viewholder is used every time, so he turns the GetView method into a oncreateviewholder. Viewholder is more suitable for lists of multiple seed layouts, especially for IM conversations. Recyclerview does not provide the Setonitemclicklistener method, you can add events in Viewholder . The use of Recyclerview can be referenced in the Material Design UI Widgets.


Recyclerview can be used for horizontal and vertical sliding views:



Recyclerview 1 Recyclerview 2


Set Landscape:

[Java]View Plaincopyprint?
  1. @Override  
  2. protected void onCreate (Bundle savedinstancestate) {
  3. Super . OnCreate (savedinstancestate);
  4. Setcontentview (r.layout.activity_recycler_view_horizontal);
  5. //Specify an adapter (see also next example)  
  6. list<myadapter.item> itemList = new arraylist<myadapter.item> ();
  7. for (int i =0; i < ; i++)
  8. Itemlist.add (new myadapter.item ("Item" + i,"World"));
  9. Madapter = new myadapter (itemList);
  10. Mrecyclerviewhorizontal = (Recyclerview) Findviewbyid (r.id.my_recycler_view_horizontal);
  11. Mrecyclerviewhorizontal.sethasfixedsize (true);
  12. //Use a linear layout manager  
  13. Linearlayoutmanager Mlayoutmanager = new linearlayoutmanager (this);
  14. Mlayoutmanager.setorientation (linearlayoutmanager.horizontal);
  15. Mrecyclerviewhorizontal.setlayoutmanager (Mlayoutmanager);
  16. Mrecyclerviewhorizontal.setadapter (Madapter);
  17. }
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_recycler_view_horizontal); Specify an adapter (see also next example) list<myadapter.item> itemList = new Arraylist<myadapter.item        > ();        for (int i = 0; i < i++) Itemlist.add (The New Myadapter.item ("Item" + I, "world");        Madapter = new Myadapter (itemList);        Mrecyclerviewhorizontal = (Recyclerview) Findviewbyid (r.id.my_recycler_view_horizontal);        Mrecyclerviewhorizontal.sethasfixedsize (TRUE);        Use a linear layout manager Linearlayoutmanager Mlayoutmanager = new Linearlayoutmanager (this);        Mlayoutmanager.setorientation (linearlayoutmanager.horizontal);        Mrecyclerviewhorizontal.setlayoutmanager (Mlayoutmanager);    Mrecyclerviewhorizontal.setadapter (Madapter); }


CardView

CardView inherits from the Framelayout class, which allows for consistent display of content in a card layout that can contain fillets and shadows. CardView is a layout that can be used to lay out other view. The use of CardView can be referenced in the Material Design UI Widgets. The article concludes with an example code for this article.



CardView Palette


Palette

Palette from the image to extract the prominent color, so that the color value can be assigned to Actionbar, or other, can make the interface of the entire tonal unity, the effect is seen (Palette).


The following prominent colors are extracted from the palette class:

Vibrant (energetic)

Vibrant Dark (vibrant dark color)

Vibrant light (vibrant bright color)

Muted (soft)

Muted dark (soft dark color)

Muted light (soft bright color)


Extract the color value code as follows:


[Java]View Plaincopyprint?
  1. Bitmap BM = Bitmapfactory.decoderesource (Getresources (), item.image);
  2. Palette Palette = palette.generate (BM);
  3. if (Palette.getlightvibrantcolor ()! =null) {
  4. Name.setbackgroundcolor (Palette.getlightvibrantcolor (). getRGB ());
  5. Getsupportactionbar (). setbackgrounddrawable (new colordrawable (Palette.getlightvibrantcolor (). getRGB ()));
  6. //Getsupportactionbar ().  
  7. }

Use of Recyclerview, CardView, palette in Android L

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.