EDITORIAL
In fact, this is the last week of school, but learned more than half, due to a variety of things failed to continue. Taking advantage of the time school on Monday has finished.
The main study of the use of a control --RecyclerView. RecyclerView is a very powerful controls, you can use it to replace listview, gridview, stagger (waterfall) and other effects, and can implement custom entries. Is a very crippled controls.
Github link code for this article: https://github.com/wushenjiang/RecyclerViewDemo
Import Package
Before use, you need to import the relevant package. We right project, select to open the manager.
In the Organizer, select
, select library Dependency, out of the input interface recyclerview
you can use the powerful RecyclerView!
Write the menu bar
In order to achieve the same activity to show, we must first write a simple menu.
Create a menu.xml, the following code:
<menu>
<item android:title="ListView效果"
android:id="@+id/list_view">
<menu>
<item android:title="垂直标准"
android:id="@+id/list_view_vertical_standard"></item>
<item android:title="垂直反向"
android:id="@+id/list_view_vertical_reverse"></item>
<item android:title="水平标准"
android:id="@+id/list_view_horizontal_standard"></item>
<item android:title="水平反向"
android:id="@+id/list_view_horizontal_reverse"></item>
</menu>
</item>
<item android:title="GridView效果"
android:id="@+id/grid_view">
<menu>
<item android:title="垂直标准"
android:id="@+id/grid_view_vertical_standard"></item>
<item android:title="垂直反向"
android:id="@+id/grid_view_vertical_reverse"></item>
<item android:title="水平标准"
android:id="@+id/grid_view_horizontal_standard"></item>
<item android:title="水平反向"
</item>
<item android:title="瀑布流效果"
android:id="@+id/stagger_view"
>
<menu>
<item android:title="垂直标准"
android:id="@+id/stagger_view_vertical_standard"></item>
<item android:title="垂直反向"
android:id="@+id/stagger_view_vertical_reverse"></item>
<item android:title="水平标准"
android:id="@+id/stagger_view_horizontal_standard"></item>
<item android:title="水平反向"
android:id="@+id/stagger_view_horizontal_reverse"></item>
</menu>
</item>
<item
android:title="多种条目类型"
android:id="@+id/multi_type"
>
</item>
</menu>
We call this xml in mainactivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch(itemId){
//ListView部分
case R.id.list_view_vertical_standard:
Log.d(TAG,"点击了ListView的垂直标准");
showList(true,false);
break;
case R.id.list_view_vertical_reverse:
Log.d(TAG,"点击了ListView的垂直反向");
showList(true,true);
break;
case R.id.list_view_horizontal_standard:
Log.d(TAG,"点击了ListView的水平标准");
showList(false,false);
break;
case R.id.list_view_horizontal_reverse:
Log.d(TAG,"点击了ListView的水平反向");
showList(false,true);
break;
//GridView部分
case R.id.grid_view_vertical_standard:
Log.d(TAG,"点击了GridView的垂直标准");
showGrid(true,false);
break;
case R.id.grid_view_vertical_reverse:
Log.d(TAG,"点击了GridView的垂直反向");
showGrid(true,true);
break;
case R.id.grid_view_horizontal_standard:
Log.d(TAG,"点击了GridView的水平标准");
showGrid(false,false);
break;
case R.id.grid_view_horizontal_reverse:
Log.d(TAG,"点击了GridView的水平反向");
showGrid(false,true);
break;
//瀑布流部分
case R.id.stagger_view_vertical_standard:
Log.d(TAG,"点击了瀑布流的垂直标准");
showStagger(true,false);
break;
case R.id.stagger_view_vertical_reverse:
Log.d(TAG,"点击了瀑布流的垂直反向");
showStagger(true,true);
break;
case R.id.stagger_view_horizontal_standard:
Log.d(TAG,"点击了瀑布流的水平标准");
showStagger(false,false);
break;
case R.id.stagger_view_horizontal_reverse:
Log.d(TAG,"点击了瀑布流的水平反向");
showStagger(false,true);
break;
//多种条目类型被点击了
case R.id.multi_type:
//跳到一个新的Activity里面来实现这个功能
Intent intent = new Intent(this,MultiTypeActivity.class);
startActivity(intent);
break;
}
return super.onOptionsItemSelected(item);
}
Achieve listview (gridview, stagger) effect
As the realization of these three are similar, there is a direct unity, just talk about ideas. CODE please see from the above in github.
First set the layout manager, set its properties, and then create the adapter, and the adapter to link RecyclerView go to. Set on the adapter see github.
To achieve the drop-down refresh
Need to use a pull-down refresh control SwipeRefreshLayout, guide package is the same method. Direct wrap RecyclerView can be. After rewriting method can in mainactivity in.
Show results
listview vertical
gridview vertical
waterfall effect
listview level
gridview level
cascade level
multiple entry type