直播商城源码,Android RecycleView 加载网络图片
1.布局
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:choiceMode="singleChoice"
android:divider="@null"
android:fadingEdge="none"
android:listSelector="@android:color/transparent"
android:scrollbarStyle="outsideOverlay"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/list_item_image2"/>
//layout 中的list_item_image2.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
>
<ImageView
android:id="@+id/iv_img"
android:layout_width="185dp"
android:layout_height="104dp"
android:scaleType="centerCrop"
android:src="@drawable/selector_image_add" />
<ImageView
android:id="@+id/iv_img2"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="centerCrop"
android:src="@mipmap/start"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
2.初始化recycleview
private NetworkImageAdapter adapter;//recyclerview 的适配器
private List<String> imagePathList;//网络图片对应的路径集合
/**
* 初始化recyclerview
* @param view
*/
private void initWidget(View view){
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
imagePathList = new ArrayList<>();
adapter = new NetworkImageAdapter(getActivity(),imagePathList);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
}
3.将图片路径填充到 imagePathList集合中,加载到adapter中;
adapter.setImages(imagePathList);//加载数据并同步显示
以上就是直播商城源码,Android RecycleView 加载网络图片, 更多内容欢迎关注之后的文章
标签:layout,adapter,RecycleView,id,源码,Android,recyclerView,android,加载 From: https://www.cnblogs.com/yunbaomengnan/p/16601807.html