<span id="Label3"></p><p style="margin-bottom:0cm;line-height:100%;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Google</span></span></span></span>In the launch<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Android5.0</span></span></span></span>Time to launch a<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">materialdesign,</span></span></span></span>Two<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>Is<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">materialdesign</span></span></span></span>One of the important components. and of Course.<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">cardview/<span style="color:#444444;"><span style="font-family:tahoma, arial, sans-serif;"><span style="font-size:11pt;">P</span></span></span><span style="color:#444444;"><span style="font-family:tahoma, arial, sans-serif;"><span style="font-size:11pt;">alette.</span></span></span> </span></span></span></span></p><p style="margin-bottom:0cm;line-height:100%;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>is used to replace the traditional<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">ListView</span></span></span></span>And<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">GridView</span></span></span></span>, the waterfall Flow Effect. Yes<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>This one control, you can achieve these three effects. While starting to use<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>Will feel some men, but with proficiency will find<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>Very Powerful. It can give every<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Item</span></span></span></span>The controls on the inside set the click Time without worrying about the event conflict, if you are using<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">ListView</span></span></span></span>or a<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">GridView</span></span></span></span>It is necessary to resolve event conflicts and even<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">ListView</span></span></span></span>Or<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">GridView</span></span></span></span>Of<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Item</span></span></span></span>You can only set a single click event, or it will cause an event conflict, which is not a good solution. So<span style="font-family:‘Liberation Serif‘, serif;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span></span>Here it comes.</p><p style="margin-bottom:0cm;line-height:100%;"><p style="margin-bottom:0cm;line-height:100%;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us"></span></span></span>First integrate <span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">Recyclerview</span></span></span>in the project, add <span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">recyclerview</span></span></span> dependencies in <span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">build.gradle</span></span></span></p></p><pre class="cjk"><pre class="cjk"><span style="font-family:arial, helvetica, sans-serif;">Compile ' com.android.support:recyclerview-v7:23.2.1 '<br>This integrates recyclerview in the project, and Android Studio will automatically download the Recyclerview package Online.</span><br></pre></pre><p style="margin-bottom:0cm;line-height:100%;"><p style="margin-bottom:0cm;line-height:100%;"><span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us"></span></span></span>In <span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">activity_main.xml</span></span></span> , use <span style="font-family:‘Liberation Serif‘, serif;"><span style="font-size:12pt;"><span lang="en-us" xml:lang="en-us">recyclerview.</span></span></span></p></p><pre class="brush:xml;toolbar:false"><pre class="brush:xml;toolbar:false"><android.support.v7.widget.recyclerview android:id= "@+id/recyclerview" android:layout_width= "match_parent" and roid:layout_height= "match_parent"/></pre></pre><p><p>The Recyclerview control is already in the layout and is now written in Code.</p></p><p><p>Explain the use of Recyclerview Here. Just like the listview, Recyclerview also needs an adapter; when we optimize the listview, we often use an internal class Viewholder to save the control in item to facilitate the reuse of the Item. And now Recyclerview must use Viewholder. This viewholder must inherit Recyclerview.viewholder,recyclerview.viewholder a constructor that has a parameter, which is passed in a view, and this view is the Recyclerview Item.</p></p><p><p>Recyclerviewholder:</p></p><pre class="brush:java;toolbar:false"><pre class="brush:java;toolbar:false">public class Recyclerviewholder extends Recyclerview.viewholder {public TextView TextView; Public ImageView ImageView; Public Recyclerviewholder (View Itemview) {super (itemview); TextView = (textView) Itemview.findviewbyid (r.id.textview); ImageView = (imageView) Itemview.findviewbyid (r.id.imageview); }}</pre></pre><p><p>Recyclerviewholder wrote the Adapter after writing it. likewise recycleradapter need to inherit recyclerview.adapter<recyclerviewholder> Generics Viewholder are self-defined recyclerviewholder. Adapter is written in the following notation:<br></p></p><pre class="brush:java;toolbar:false">public class recycleradapter extends recyclerview.adapter<recyclerviewholder> { private List<Map<String, String>> dataList; public recycleradapter () { dataList = new arraylist<> (); } public void AddAll (list<map<string, string>> data) { Datalist.addall (data); } /** * * @param viewType corresponds to the value returned by the Getitemviewtype (int position) method */ @Override public Recyclerviewholder oncreateviewholder (viewgroup parent, int viewtype) { View view = layoutinflater.from (parent.getcontext ()). Inflate (r.layout.item, parent, false); return new recyclerviewholder (view); } /** * * @param holder corresponds to the Oncreateviewholder method, the returned recyclerviewholder * @param position Location of the current item */ @Override public void onbindviewholder (recyclerviewholder holder, int Position) { holder.textview.settext (dataList.get (position) . Get ("data")); } @Override public Int getitemcount () { return datalist.size (); }}</pre><p>The code in the <p> Mainactivity. </p></p><pre class="brush:java;toolbar:false">Public class mainactivity extends appcompatactivity { private recyclerview recyclerview; //using the linear layout manager, set the direction orientation is the default, that is, vertical direction private linearlayoutmanager manager; //adapter private recycleradapter adapter; //data Source private List<Map<String, String>> list; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); recyclerview = (recyclerview) findviewbyid (r.id.recyclerview); Manager = new linearlaYoutmanager (this); adapter = new recycleradapter (); //set layout Manager Recyclerview.setlayoutmanager (manager); //set Adapter for RecyclerView recyclerview.setadapter (adapter); list = new ArrayList<> (); for (int i=0;i<50;i++) { map<string,string> map = new HashMap<> (); map.put ("data") , "item--> " +i); list.add (map); &nbsP; } adapter.addall (list); adapter.notifydatasetchanged (); }}</pre><p><p>Recyclerview implementation of the ListView effect is complete, running effect:</p></p><p><p>650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/7D/CB/wKiom1bwAm6gFtn-AACorefEJoQ425.png "title=" Recyclerview implementation of the ListView effect "alt=" wkiom1bwam6gftn-aacorefejoq425.png "/></p></p><p><p>If you want each item to slide horizontally, you only need to use Linearlayoutmanager's three-parameter construction method, New Linearlayoutmanager (this, linearlayoutmanager.horizontal, True) to achieve the effect of transverse sliding.</p></p><p><p>Recyclerview implements the GridView Effect. Need to be used is gridlayoutmanager. Replace the Recyclerview layout manager with Gridlayoutmanager manager = new Gridlayoutmanager (this, 2) as Follows:<br></p></p><p><p>650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/7D/CB/wKiom1bwBiXzf2LxAADEl4akjZo408.png "title=" Recyclerview implementation of the GridView effect "alt=" wkiom1bwbixzf2lxaadel4akjzo408.png "/></p></p><p><p>Recyclerview the effect of waterfall flow another piece of article Explained.</p></p><p><p>This article is from the "Meu late injury" blog, Please be sure to keep this source http://zzhhz.blog.51cto.com/7107920/1753676</p></p><p><p>Basic use of Android Recyclerview</p></p></span>
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