implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api 'com.github.bumptech.glide:glide:4.13.2'
api 'com.github.bumptech.glide:annotations:4.13.2'
kapt 'com.github.bumptech.glide:compiler:4.13.2'
api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7'
api "androidx.recyclerview:recyclerview:1.2.0"
api 'com.github.penfeizhou.android.animation:apng:2.23.0'
api 'com.github.penfeizhou.android.animation:glide-plugin:2.23.0'
所有设备均可复现
MainActivity 集合数据放不同的 png url
package com.test.myapplication import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activitymain) val recyclerView = findViewById(R.id.recyclerView)
val imageAdapter = ImageAdapter(
mutableListOf(
ImageBean("73746.png"),
ImageBean("11420.png"),
ImageBean("55232.png"),
ImageBean("27916.png"),
ImageBean("89571.png"),
ImageBean("97790.png"),
ImageBean("64916.png")
)
)
recyclerView.apply {
layoutManager = LinearLayoutManager(context)
adapter = imageAdapter
imageAdapter.setOnItemClickListener { , _, position ->
imageAdapter.data[position].check = !imageAdapter.data[position].check
imageAdapter.notifyItemChanged(position)
}
}
}
}
适配器
` package com.test.myapplication
import androidx.appcompat.widget.AppCompatImageView import com.bumptech.glide.Glide import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.viewholder.BaseViewHolder
class ImageAdapter(data: MutableList?) :
BaseQuickAdapter<ImageBean, BaseViewHolder>(R.layout.item_image_layout, data) {
} `
glide配置 ` package com.test.myapplication
import com.bumptech.glide.annotation.GlideModule import com.bumptech.glide.module.AppGlideModule
@GlideModule class SelfGlideModule : AppGlideModule() `
bean ` package com.test.myapplication
data class ImageBean( var url: String = "", var check: Boolean = false )
item_image_layout布局
<?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"></androidx.appcompat.widget.LinearLayoutCompat> `
activity_main布局 ` <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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">
</androidx.constraintlayout.widget.ConstraintLayout> `
build.gradle ` dependencies { implementation fileTree(dir: "libs", include: ["*.jar"])
} `