Recyclerview is derived from the ListView, which is more efficient than the ListView and is more convenient to use.
This article explains how to do this with Recyclerview: vertical list effects, landscape list effects, grid list effects , waterfall flows (Landscape and portrait), and Item's Click to listen (because Recyclerview does not have the item's click to listen function, here is my self-created, the feeling is still useful). That's a powerful effect, isn't it? Haha, see the source code below
(1) Main layout
<?XML version="1.0"encoding="Utf-8"?>
<relativelayoutxmlns:Android="Http://schemas.android.com/apk/res/android"
Android: Layout_width="Match_parent"
Android: layout_height="Match_parent">
<android.support.v7.widget.recyclerview
Android: id="@+id/recyclerview"
Android: Layout_width="Match_parent"
Android: layout_height="Match_parent"/>
</RelativeLayout>
(2) Item
<?XML version="1.0"encoding="Utf-8"?>
<linearlayoutxmlns:Android="Http://schemas.android.com/apk/res/android"
Android: Layout_width="Match_parent"
Android: layout_height="Match_parent"
Android: orientation="Vertical">
<textview
Android: id="@+id/tv"
Android: textsize="60DP"
Android:p adding="20DP"
Android: Layout_width="Wrap_content"
Android: layout_height="Wrap_content"/>
</LinearLayout>
(3) Mainactivity code
Mainactivity appcompatactivity {Recyclerview string[] = {} (Bundle savedinstancestate) {. OnCreate (Savedinstanc eState) Setcontentview (r.layout.) = (Recyclerview) Findviewbyid (r.id.). Sethasfixedsize () Staggeredgridlayoutmanager Staggeredgridlayoutmanager =staggeredgridlayoutmanager ( Staggeredgridlayoutmanager.). Setlayoutmanager (Staggeredgridlayoutmanager). Setadapter (Myadapter ())
(4) Adapter Adapter
myadapter recyclerview.adapter<myadapter.viewholder>{ string[] Myadapter (String[] mdatas) { =mdatas} ViewHolder (Viewgroup parentviewtype) { View view=layoutinflater. (Parent.getcontext ()). Inflate (r.layout.parent) Viewholder viewholder=viewholder (Viewparent.getContext ()) viewholder} (viewholder holderposition) { holder. SetText ([position])} () { .} ViewHolder RecyclerView.ViewHolder View.OnClickListener { textview context viewholder (view itemviewcontext Context) { (Itemview) =&NBSP; (TextView) itemview.findviewbyid (r.id.). =contextitemview.setonclicklistener ()} (View v) { toast. (. GetText (). toString () Toast.). Show ()} }}
Operating effect:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/76/5E/wKioL1ZRpXTCMveKAACk36iRDlM932.jpg "title=" Qq20151122192043.jpg "alt=" Wkiol1zrpxtcmvekaack36irdlm932.jpg "/>
This article is from the "Mobile Platform Development" blog, make sure to keep this source http://liuxudong1001.blog.51cto.com/10877072/1715723
How to use Recyclerview and how to set up tap listening