android - 反转 GridRecyclerView Kotlin 中的空白
问题描述
所以这是我的 GridLayout 我已经声明了 LinearLayoutManager.VERTICAL, true
var recyclerViewUploaded: RecyclerView? = null
recyclerViewUploaded = my_posts_recycle
recyclerViewUploaded.setHasFixedSize(true)
val gridLayoutManager = GridLayoutManager(this, 2, LinearLayoutManager.VERTICAL, true )
recyclerViewUploaded.layoutManager = gridLayoutManager
postList = ArrayList()
postAdapter = MypostsAdapter(this, postList as ArrayList<Post>)
recyclerViewUploaded.adapter = postAdapter
见上图,问题是它在顶部而不是底部留下了一个空白区域。
我曾尝试使用 Collections.reverse(postList) 但它给出了意想不到的结果,即 post order 123456 变为 125643 而不是 654321。
postList.reverse() 也不做任何事情!
这是我检索图像的功能。
private fun retrievePosts() {
val postsRef = FirebaseDatabase.getInstance().reference.child("Posts")
postsRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
(postList as ArrayList<Post>).clear()
for (snapshot in dataSnapshot.children) {
val post = snapshot.getValue(Post::class.java)
if (post!!.getPublisher() == profileId) {
(postList as ArrayList<Post>).add(post)
}
if (postList.isNullOrEmpty()){
swipe_refresh_profile.isRefreshing = false
}
postList!!.reversed()
swipe_refresh_profile.isRefreshing = false
postAdapter!!.notifyDataSetChanged()
}
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
}
)
}
这是我的 JSON 数据库结构
"Posts" : {
"-MYkL70voeqXhrkli7vE" : {
"caption" : "Setup by:- @iamlokesh_04\n\nSector Kwgt\nhttps://play.google.com/store/apps/details?id=sector.kustom.pack\n\nMini-music Kwgt\nhttps://play.google.com/store/apps/details?id=minimusicplayerforkwgt.kustom.pack\n\nSelf-made icons\nhttps://t.me/Iamlokesh_04\n\nHope you guys like it ",
"postid" : "-MYkL70voeqXhrkli7vE",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940031310.jpg?alt=media&token=946e7836-b032-4d95-93ac-1c04d4342161",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
},
"-MYkLhERZIZ5az-K3VrQ" : {
"caption" : "Alpplications used: #37\n\n+Launcher - Nova launcher\n\n+Widgets - https://play.google.com/store/apps/details?id=flawlesskwgt.kustom.pack \n\n+Icon Pack - https://play.google.com/store/apps/details?id=com.panotogomo.darktosca\n\n+Wallpaper - https://play.google.com/store/apps/details?id=com.stark.fluid\n\nTemplate by - https://twitter.com/vhthinh_at?s=09 ",
"postid" : "-MYkLhERZIZ5az-K3VrQ",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940184176.jpg?alt=media&token=f6ced789-be42-4d72-873f-8316ce557ff9",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
},
"-MYkLpNkeHPEWwmYDgwN" : {
"caption" : "Rate my Setup!! ",
"postid" : "-MYkLpNkeHPEWwmYDgwN",
"postimage" : "https://firebasestorage.googleapis.com/v0/b/android-customization.appspot.com/o/Posted%20Pictures%2FAkZI2A4EZbMOHCHPqZp4h4hl2zL2%2F1618940216883.jpg?alt=media&token=59c0b67e-bd5c-4b6c-9c14-36e16676bf58",
"publisher" : "AkZI2A4EZbMOHCHPqZp4h4hl2zL2"
}
]
在这里,如果帖子的发布者 ID 与配置文件 ID 相同,则会将其添加到 postList 列表中。
我一直在寻找解决方案,任何帮助将不胜感激!
解决方案
推荐阅读
- java - 如何强制 Java 每个字符仅使用 2 个字节作为 Unicode 字符(例如“ł”)?
- java - 如何解决postgresql中的查询没有返回结果?
- sql - 根据其在第一个表中的存在,将来自另一个表的数据附加到组
- java - 如何在 Flink 中使用 LocalDate 字段有效地序列化 POJO?
- python - 带有 nans 的 3D 数组并使用 scipy 去趋势
- extjs - 7.x MODERN treegrid - nodecollapse/nodeexpand 事件:空行参数
- java - 在通过 JAVA 代码扫描文件时输入密码
- reactjs - 应用程序未运行时不显示 PWA 推送通知
- react-native - 反应本机链接无法正常工作
- events - 如何通过 Microsoft Graph API 搜索日历事件?