依赖
implementation 'com.squareup.okhttp3:okhttp:3.1.2'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.facebook.fresco:fresco:0.12.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
定义一个接口
public interface Api {
@GET("meinv/?key=71e58b5b2f930eaf1f937407acde08fe&num=10")
Call<Movie> getMovie(@Query("page") int page);
}
封装工具类
public class HttpUtil {
public static HttpUtil getInstance(){
return httpUtilInter.httpUtil;
}
private static class httpUtilInter{
private static HttpUtil httpUtil=new HttpUtil();
}
public final Api api;
private HttpUtil() {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl("http://api.tianapi.com/")
.build