Turn:
http://blog.csdn.net/xyz_lmn/article/details/38735117
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
If you have tried the SDK for Android Lollipop, you may have noticed the palette. Palette extract the prominent color from the image, so that the color value can be assigned to Actionbar, or other, can make the interface of the whole tone unified.
Creating an Palette instance
There are four ways to create an instance:
1234567891011121314151617181920212223242526 |
// Synchronous methods.
// --------------------------------
// These should be used when you have access to the underlying image loading thread.
// Picasso allows this through a Transformation. For other libraries, YMMV.
// Uses the default palette size (16).
Palette p = Palette.generate(bitmap);
// Allows you to specify the maximum palette size, in this case 24.
Palette p = Palette.generate(bitmap, 24);
// Asynchronous methods
// --------------------------------
// This is the quick and easy integration path. Internally uses an AsyncTask so
// this may not be optimal (since you‘re dipping in and out of threads)
// Uses the default palette size (16).
Palette.generateAsync(bitmap,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// Here‘s your generated palette
}
});
// Allows you to specify the maximum palette size, in this case 24.
Palette.generateAsync(bitmap, 24,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// Here‘s your generated palette
}
});
|
After creating an instance, we also need to get a sample of the samples (Swatch), with 6 samples (swatch):
123456 |
Vibrant. Palette.getVibrantSwatch() Vibrant dark. Palette.getDarkVibrantSwatch() Vibrant light. Palette.getLightVibrantSwatch() Muted. Palette.getMutedSwatch() Muted dark. Palette.getDarkMutedSwatch() Muted light. Palette.getLightMutedSwatch() |
Depending on who you choose, most of the cases we use vibrant and Dark vibrant.
Using Samples (swatch)
Swatch has the following methods:
12345 |
getpopulation (): The amount of pixels which this swatch represents. getrgb (): The RGB value of this color. GETHSL (): The HSL value of this color. getbodytextcolor (): The RGB value of a text color which can be displayed on top of this color. gettitletextcolor (): The RGB value of a text color which can be displayed on top of this color. |
For example, if your textview has a background image, if you want to make the font color and background image match, then use getBodyTextColor()
more appropriate, in getTitleTextColor()
fact, should and getBodyTextColor()
almost.
The following code shows how to extract a color from a picture to set the background color of the TextView to the main color of the picture, and then use getTitleTextColor
() to set a matching text color.
123456 |
Palette.Swatch swatch = palette.getVibrantSwatch(); TextView titleView = ...; if (swatch != null ) { titleView.setBackgroundColor(swatch.getRgb()); titleView.setTextColor(swatch.getTitleTextColor()); } |
It is important to note that getVibrantSwatch()
a null value may be returned, so it is necessary to check it.
Problem with size
You can also use the following methods to get all of the swatch at once:
1 |
List<Palette.Swatch> swatches = palette.getSwatches(); |
In the above code, you may have noticed that you can set the size of the palette. The larger the size, the longer it takes, and the smaller the color you can choose. The best choice is based on the use of Image:
Avatar and the like, the size of the best between 24-32;
The size of the big picture is almost 8-16;
The default is 16.
===================================================================================================
Palette extract the prominent color from the image, so that the color value can be assigned to Actionbar, or other, can make the interface of the whole tone unified.
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 ().
- }
Android L Recyclerview, CardView, Palette