Later android-BASIC programming * is the control demo inside, no longer cumbersome rewrite. Describes the control's use directly.
Recyclerview is a more advanced and flexible version of the ListView. This widget was a Container for large sets of views of the can be recycled and scrolled very efficiently. Recyclerview was released from 2014. Located in Android.support.v7.widget.RecyclerView.
1.android Studio Configuration Recyclerview Library code
Join in the Gradle
Compile ' com.android.support:recyclerview-v7:23.+ '
2. Defining layouts in use
< Android.support.v7.widget.RecyclerView Android:id = "@+id/recycle_view" android:layout_width= "Match_parent" android:layout_height= "Match_ Parent "> </android.support.v7.widget.RecyclerView>
Also want to recycleview the layout of the item:
<Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:background= "#44ff0000"Android:layout_height= "Wrap_content" > <TextViewAndroid:id= "@+id/id_num"Android:layout_width= "Match_parent"Android:layout_height= "50DP"android:gravity= "Center"Android:text= "1" /></Framelayout>
3. Use in Rcyclerviewacti
A. Load the view layout:
Recyclerview = (Recyclerview) Findviewbyid (R.id.recycle_view);
B. Setting up layout management LayoutManager
Recyclerview.setlayoutmanager (new Linearlayoutmanager (this));
There are currently three LayoutManager available in the SDK, namely thread, grid, waterfall layout Manager:
C. Configuring a data source
New Recycleradapter (this); Adapter.setdata (Mdatas); // Adaoter Recyclerview.setadapter (Adapter) must be specified;
4. Click events, recycler do not support Click events, you need to implement
A. In the adapter definition the interface is implemented as follows:
public static interface Onrecyclerviewitemclicklistener { void Onitemclick (view view, int POS); // 2 add interface and set interface method private Onrecyclerviewitemclicklistener monitemclicklistener = null Span style= "color: #000000;" >; public void Setonitemclicklistener (Onrecyclerviewitemclicklistener listener) { this.monitemclicklistener = listener; }
B.adater Implement View Click events
@Override Public void OnClick (View v) { //toast.maketext (GET, "default Toast Style"). Show (); LOG.D ("Zcx", "Test"); if NULL { //Call Onitemclick Monitemclicklistener.onitemclick (v,1);}
C. Calling Onitemclick
Adapter.setonitemclicklistener (new Recycleradapter.onrecyclerviewitemclicklistener () { @ Override publicvoidint pos) { //doyour fucking Bussiness here! Adapter.adddata (1); Toast.maketext (Getapplicationcontext (),"zcx" +Pos,toast.length_long). Show (); });
5.item Animation effect:
Recyclerview.setitemanimator (new defaultitemanimator ());
The results of the final experiment are as follows:
android-BASIC Programming-recyclerview