Material Design mentions that Recyclerview, CardView, and Palette have been added to the Android L version. Recyclerview, CardView are new widgets for displaying complex views. Palette, as a palette class, lets you extract prominent colors from an image.
Recyclerview
Recyclerview as an alternative to the ListView use, Recyclerview standardized viewholder,listview in Convertview 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?
- @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 (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?
- Bitmap BM = Bitmapfactory.decoderesource (Getresources (), item.image);
- Palette Palette = palette.generate (BM);
- if (palette.getlightvibrantcolor () = null) {
- Name.setbackgroundcolor (Palette.getlightvibrantcolor (). getRGB ());
- Getsupportactionbar (). setbackgrounddrawable (new Colordrawable (Palette.getlightvibrantcolor (). GETRGB ()));
- //Getsupportactionbar ().
- }
Use of Recyclerview, CardView, palette in Android L