0
点赞
收藏
分享

微信扫一扫

【探索AI】十一 深度学习之机器学习基础

小云晓云 03-03 16:00 阅读 2
android

1. 在 build.gradle 中添加依赖

// 下拉刷新,上拉加载更多
// https://github.com/scwang90/SmartRefreshLayout
implementation 'io.github.scwang90:refresh-layout-kernel:2.1.0'      //核心必须依赖
implementation 'io.github.scwang90:refresh-header-classics:2.1.0'    //经典刷新头
implementation 'io.github.scwang90:refresh-footer-classics:2.1.0'    //经典加载

2. 如果使用 AndroidX 先在 gradle.properties 中添加。因为这个第三方库里有用到旧版的 Support 依赖包。android.enableJetifier=true 这个属性的作用可以简单理解为,如果自己的项目为 AndroidX,但也用到了一些第三方库,而第三方库里面还用的是旧版的依赖。这种情况下就会发生冲突。android.enableJetifier=true 这个属性就会在编译的时候把第三方依赖里面的旧版依赖换成我们 AndroidX 里的依赖。

android.useAndroidX=true
android.enableJetifier=true

3. activityMain.xml

<?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">

    <com.scwang.smart.refresh.layout.SmartRefreshLayout
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <com.scwang.smart.refresh.header.ClassicsHeader
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="RecyclerView"
            android:textSize="35sp"
            android:gravity="center"/>

        <com.scwang.smart.refresh.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </com.scwang.smart.refresh.layout.SmartRefreshLayout>

</LinearLayout>

4. MainActivity.kt

class MainActivity : AppCompatActivity() {
    private lateinit var smartRefreshLayout : SmartRefreshLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        smartRefreshLayout = findViewById(R.id.smart_refresh_layout)

        // TODO 下拉刷新
        smartRefreshLayout.setOnRefreshListener {
            // TODO do something 请求最新的网络数据
            //...
            // TODO 完成刷新,参数2:是否刷新成功;参数2:是否还有更多数据
            smartRefreshLayout.finishRefresh(500, true, false)
        }

        // TODO 下拉加载更多
        smartRefreshLayout.setOnLoadMoreListener {
            // TODO do something 请求更多的网络数据
            //...
            // TODO 完成加载更多,参数2:是否刷新成功;参数2:是否还有更多数据
            smartRefreshLayout.finishLoadMore(500, true, true)
        }

    }
}
举报

相关推荐

0 条评论