一、recycleview的基本使用
效果图:
项目结构:
代码实现:
在这之前往项目build.gradle(app)文件中加入依赖
1.info_item文件中代码实现
只加入了一个textview,比较简单
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="40sp"
android:textColor="#000"
android:textStyle="bold"
android:gravity="center"
android:text="info" />
</LinearLayout>
2.activity_main文件中加入recycleview控件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dd8855">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
3.新建Info.java文件
package com.example.recyclerviewtest;
/**
* Created by Administrator on 2019/3/28.
*/
public class Info {
private String content;
public Info(String content){
this.content = content;
}
public String getContent(){
return content;
}
}
4.构造适配器InfoAdapter
package com.example.recyclerviewtest;
/**
* Created by Administrator on 2019/3/28.
*/
import android.support.v7.widget