<android.support.v7.widget.CardView
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/item_list_iv"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="8dp"/>
<TextView
android:id="@+id/item_list_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="内容"
android:textSize="24sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
2.修改布局管理器从大到ListView,GridView,瀑布流的效果
private void initList()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
LinearLayoutManager layoutManager = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL,
false);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new ListAdapter(this,
mListDatas));//adapter ---> list数据
}
private void initGrid()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
GridLayoutManager layoutManager = new GridLayoutManager(this,
2,
GridLayoutManager.VERTICAL,
false);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new ListAdapter(this,
mListDatas));//adapter ---> list数据
}
private void initStragger()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,
StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new StraggerdAdpater(this,
mStraggerDatas));//adapter ---> list数据
}
3.瀑布了需要改item的样式Card
4.下拉刷新:
在外面套一层----------
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
@Override
public void onRefresh()
{
//下拉刷新时的回调
new AsyncTask<Void, Void, Void>()
{
@Override
protected Void doInBackground(Void... params)
{
try
{
Thread.sleep(3000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
if (adapter instanceof ListAdapter)
{
//给list加载数据
for (int i = 0; i < mListIcons.length; i++)
{
DataBean bean = new DataBean();
bean.icon = mListIcons[i];
bean.content = "内容-" + i;
mListDatas.add(bean);
}
} else if (adapter instanceof StraggerdAdpater)
{
//给stragger加载数据
for (int i = 0; i < mStraggeredIcons.length; i++)
{
DataBean bean = new DataBean();
bean.icon = mStraggeredIcons[i];
bean.content = "内容-" + i;
mStraggerDatas.add(bean);
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid)
{
super.onPostExecute(aVoid);
RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
//adatper刷新
adapter.notifyDataSetChanged();
//通知刷新的view刷新完成
mRefreshLayout.setRefreshing(false);
}
}.execute();
}
<android.support.v7.widget.CardView
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/item_list_iv"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="8dp"/>
<TextView
android:id="@+id/item_list_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="内容"
android:textSize="24sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
2.修改布局管理器从大到ListView,GridView,瀑布流的效果
private void initList()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
LinearLayoutManager layoutManager = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL,
false);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new ListAdapter(this,
mListDatas));//adapter ---> list数据
}
private void initGrid()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
GridLayoutManager layoutManager = new GridLayoutManager(this,
2,
GridLayoutManager.VERTICAL,
false);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new ListAdapter(this,
mListDatas));//adapter ---> list数据
}
private void initStragger()
{
//实现listView的效果
// 可以垂直滑动,也可以水平滑动,数据反向加载
//设置布局管理器
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,
StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
//设置adapter
mRecyclerView.setAdapter(new StraggerdAdpater(this,
mStraggerDatas));//adapter ---> list数据
}
3.瀑布了需要改item的样式Card
4.下拉刷新:
在外面套一层----------
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
@Override
public void onRefresh()
{
//下拉刷新时的回调
new AsyncTask<Void, Void, Void>()
{
@Override
protected Void doInBackground(Void... params)
{
try
{
Thread.sleep(3000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
if (adapter instanceof ListAdapter)
{
//给list加载数据
for (int i = 0; i < mListIcons.length; i++)
{
DataBean bean = new DataBean();
bean.icon = mListIcons[i];
bean.content = "内容-" + i;
mListDatas.add(bean);
}
} else if (adapter instanceof StraggerdAdpater)
{
//给stragger加载数据
for (int i = 0; i < mStraggeredIcons.length; i++)
{
DataBean bean = new DataBean();
bean.icon = mStraggeredIcons[i];
bean.content = "内容-" + i;
mStraggerDatas.add(bean);
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid)
{
super.onPostExecute(aVoid);
RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
//adatper刷新
adapter.notifyDataSetChanged();
//通知刷新的view刷新完成
mRefreshLayout.setRefreshing(false);
}
}.execute();
}