Simple implementation of Android recyclerview loading different layouts
preface
I won't repeat the use of recyclerview here. I believe there are a lot of online searches (my previous articles also have a brief introduction to the use). This time, we are talking about the simple implementation of different layouts sometimes loaded according to different locations during the use of recyclerview. This is just to attract jade
design sketch
Design idea • rewrite getitemviewtype (int position) of recyclerview.adapter. In this method, set different ViewTypes according to different positions • write specific subclasses of recyclerview.viewholder (different subclasses correspond to different views or layouts) • rewrite oncreateviewholder (ViewGroup parent, int viewtype) of recyclerview.adapter In this method, we return different subclasses of recyclerview.viewholder according to the viewtype we set earlier
code
Using recyclerview requires adding dependencies
compile 'com.android.support:recyclerview-v7:24.1.1'
The first is the mainactivity layout, a very simple layout
Then comes the mainactivity code
Then our adapter
Next is our custom divideritemdecoration
Project address: https://github.com/Greathfs/RecyclerViewLoadLayout
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.