本文章使用了RecyclerView作为替代listVIew,OKHTTP网络框架请求数据,图片展示使用的是Glide、Gson解析
所以需要导入依赖
OKHTTP依赖
compile 'com.squareup.okhttp3:okhttp:3.9.0'
Gson依赖
compile 'com.google.code.gson:gson:2.8.1'
Glide依赖
compile 'com.github.bumptech.glide:glide:4.0.0'
recyclerview依赖
compile 'com.android.support:recyclerview-v7:25.3.1-alpha1'
如果导入RecycleView依赖时与V7包冲突,在module 的 build.gradle配置文件里最后面加上这一段
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}
}
activity_main布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.gss.recycleviewdemo.MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerview"

该博客介绍了如何在Android应用中使用RecyclerView替换ListView,通过OKHTTP进行网络数据请求,利用Gson进行JSON解析,并采用Glide展示图片的瀑布流布局。文中详细讲解了各个依赖的引入、接口定义、Bean类、Adapter的泛型使用方法及Item布局的创建过程。
最低0.47元/天 解锁文章
2410

被折叠的 条评论
为什么被折叠?



