1.使用的开发工具:Android Studio 3.1.1,工程目录如下:
2.新建工程,命名为:RecyclerViewTest空工程,导入RecyclerView控件的依赖库:
步骤如下:
打开app/build.gradle,修改后内容如下:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
或者也可以通过设置project structure里面的Dependencies点击右上角“+”号输入
com.android.support:recyclerview-v7:27.1.1
进行添加,然后点击file/Sync Project With Gradle Files进行同步,至此,导入依赖包成功!
3.修改activity_main.xml中代码为:
<?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="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
这就是我们的手机打开软件后的页面。
然后我们需要定制一个界面控件(即我们需要在软件页面中加入显示的内容),我的设计(一个imagevie