reprint Please specify Http://blog.csdn.net/eclipsexys translation from developer Android, time haste, there are translation questions please note that, thank you
creating LISST and Cards
Create complex checklists in your application, and with material design style cards, you can use Recyclerview and CardView widgets.
Create Recyclerview
The Recyclerview widget is a more advanced, more flexible version of the ListView. This gadget is a container for display that can be very effective in maintaining a limited number of views, scrolling large data sets. When you have collected data, its elements change at run time based on user behavior and network events using Recyclerview widgets.
The Recyclerview class simplifies, providing the display and processing of large data sets:
Locating the Project layout Manager
The default animation is a common item action, such as deleting or adding items
You can also define the flexibility of custom layout manager and animations in the Recyclerview part.
To use the Recyclerview widget, you must specify an adapter and a layout manager. To create an adapter, extend the Recyclerview.adapter class. The details of the implementation depend on the specifics of your data set and the type of opinion. For more information, see the example below.
Recyclerview the internal layout manager's position on the project's views and determines when the view of reusing items is no longer visible to the user. To reuse (or recycle) a diagram, the layout manager may ask the adapter to replace the contents of the view with a different element of the dataset. The idea of recycling in this way increases the lookup performance by avoiding unnecessary views or performing expensive Findviewbyid ().
Recyclerview provides these built-in layout managers:
Linearlayoutmanager is displayed in a vertical or horizontal scrolling list item.
Gridlayoutmanager items that appear in the grid.
Staggeredgridlayoutmanager displays staggered grid items.
To create a custom layout manager, extend the Recyclerview.layoutmanager class.
Animation
Animations are added and deleted in the project by default Recyclerview enabled. To customize these animations, inherit the Recyclerview.itemanimator class and use the Recyclerview.setitemanimator () method.
Examples
The following code example shows how to add Recyclerview to a layout:
<!--A Recyclerview with some commonly used attributes--><android.support.v7.widget.recyclerview Android : id= "@+id/my_recycler_view" android:scrollbars= "vertical" android:layout_width= "Match_parent " android:layout_height= "Match_parent"/>
Once you have added a Recyclerview widget layout, get the handle object, connect it to a layout manager, and attach the data adapter to display:
public class MyActivity extends Activity {private Recyclerview mrecyclerview; Private Recyclerview.adapter Madapter; Private Recyclerview.layoutmanager Mlayoutmanager; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.my_activity); Mrecyclerview = (Recyclerview) Findviewbyid (R.id.my_recycler_view); Use this setting to improve performance if you know so changes//in content does not change the layout size of The Recyclerview mrecyclerview.sethasfixedsize (true); Use a linear layout manager Mlayoutmanager = new Linearlayoutmanager (this); Mrecyclerview.setlayoutmanager (Mlayoutmanager); Specify an adapter (see also next example) Madapter = new Myadapter (myDataSet); Mrecyclerview.setadapter (Madapter); } ...}
The adapter provides access to information in your dataset, creating a view of the item, replacing the contents of some new data item's view when the original product is no longer visible. The following code example shows a simple implementation of a set of data that is displayed by using a TextView widget of a string array:
public class Myadapter extends recyclerview.adapter<myadapter.viewholder> {private string[] mdataset; Provide a reference to the "view for each data item//COMPLEX data items * need more than one views per item, and You provide access to all of the views for a data item in a view holder public static class Viewholder extends Recyc Lerview.viewholder {//each of the data item is just a string "in the" case "public TextView Mtextview; Public Viewholder (TextView v) {super (V); Mtextview = v; }}//provide a suitable constructor (depends on the kind in dataset) public Myadapter (string[] mydataset) { Mdataset = myDataSet; }//Create new Views (invoked by the layout manager) @Override public Myadapter.viewholder Oncreateviewholder (Vi Ewgroup parent, int viewtype) {//Create a new View view v = layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.my_text_view, parent, false); Set the view ' s size, margins, paddings and layout parameters ... Viewholder VH = new Viewholder (v); return VH; }//Replace the contents of a view (invoked by the layout manager) @Override public void Onbindviewholder (viewho Lder holder, int position) {//-get element from your dataset at this position//-Replace the contents O f The view with that element Holder.mTextView.setText (Mdataset[position]); }//Return the size of your dataset (invoked by the layout manager) @Override public int GetItemCount () { return mdataset.length; }}
Create CardView
CardView extends the Framelayout class and allows you to display information that has a cross-platform consistent appearance card inside. CardView parts can have shadows and rounded corners.
To create a shadow card, use the Card_view:cardelevation property. CardView uses real elevation and dynamic shading above the Android5.0 (API level 21) and falls back to the earlier version of the programmatic shadow implementation. For more information, see Maintaining compatibility.
Use these properties to customize the appearance of the CardView widget:
To set the fillet radius in your layout, use the Card_view:cardcornerradius property.
To set the radius of the fillet in your code, use the Cardview.setradius method.
Sets the background color of the card, using the Card_view:cardbackgroundcolor property.
The following code example shows how to CardView a part in your layout:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " xmlns:card_view=" Http://schemas.android.com/apk/res-auto "... > <! --a CardView that contains a TextView to <android.support.v7.widget.cardview xmlns:card_view= "http:// Schemas.android.com/apk/res-auto " android:id=" @+id/card_view " android:layout_gravity=" center " Android:layout_width= "200DP" android:layout_height= "200DP" card_view:cardcornerradius= "4DP" > <textview android:id= "@+id/info_text" android:layout_width= "match_parent" android:layout_ height= "Match_parent"/> </android.support.v7.widget.CardView></LinearLayout>
Creating Apps with Material design--creating Lists and Cards