1加入联网权限
<uses-permission android:name="android.permission.INTERNET"/>
2.搜索添加依赖
import android.support.v7.widget.RecyclerView;
3在build.gradle加入glide 进行图片的解析
compile 'com.github.bumptech.glide:glide:3.8.0'
主页面布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="线性布局"
android:id="@+id/btn_xian"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="表格布局"
android:id="@+id/btn_biao"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="瀑布流"
android:id="@+id/btn_pu"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:id="@+id/recyclerview"></android.support.v7.widget.RecyclerView>
</LinearLayout>
Bean包写下User类
public class User {
private String name;
private String avatar;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
}
为了方便编写先把adapter写好,再先MainActivity吧
线性adapter LinearAdapter