首先我们先引入我们所需要的依赖
//流失布局需要的依赖
implementation 'com.hyman:flowlayout-lib:1.1.2'
implementation 'com.android.support:design:28.0.0'
//recycler的依赖
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
//okgo
implementation 'com.lzy.net:okgo:3.0.4'
//Glide加载图片
implementation 'com.github.bumptech.glide:glide:3.7.0'
//解析数据
implementation 'org.kie.modules:com-google-code-gson:6.5.0.Final'
//xrecycle
implementation 'com.jcodecraeer:xrecyclerview:1.5.9'
如果build报错在最外层gradle加入
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" } //加入
}
}
其次是清单文件写权限
//联网权限
<uses-permission android:name="android.permission.INTERNET" />
//写
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
//读
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
首页显示的流式布局 xml布局
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索历史"
android:textSize="30sp"
/>
<com.zhy.view.flowlayout.TagFlowLayout
android:id="@+id/id_flowlayout"
app:max_select="-1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp">
</com.zhy.view.flowlayout.TagFlowLayout>
需要写一个圆角的text条目
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/shape"
android:text="Helloworld"
android:textColor="#000"
android:textSize="20sp"
android:padding="10dp"
>
</TextView>
下方是显示多条目的布局
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/recycle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></com.jcodecraeer.xrecyclerview.XRecyclerView>
下方就是recyleView的多条目的三种布局
第一种布局
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="1"
>
<TextView
android:id="@+id/text_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="25sp"
/>
<TextView
android:id="@+id/text_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="15sp"
android:textColor="#6666"
/>
</LinearLayout>
<ImageView
android:id="@+id/image_icon"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@mipmap/ic_launcher"
/>
第二种布局
<Line