【发布时间】:2019-12-31 06:42:53
【问题描述】:
我使用了一个 RecyclerView,它使用 LayoutManager 调整为水平形状, 我把我的 RecyclerView 放在 HorizontalScrollView 中,效果很好,在 Android Studio 的 android 模拟中,而在真机中,它可以工作一些时间!我的意思是它滚动了一点,不能完全滚动,但如果你突然尝试滚动它,它可以完全滚动。
这是我的回收站查看代码:
<HorizontalScrollView
android:id="@+id/scrollbar"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_challenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
这些代码显示了我如何在 Fragment 中使用 RecyclerView:
val recyclerView = view.findViewById<RecyclerView>(R.id.recycler_challenge)
recyclerView.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false)
val challenges = ArrayList<challenge_model>()
challenges.add(challenge_model("https://pic1.jpg", "picture one", false,"pic_1"))
challenges.add(challenge_model("https://pic1.jpg", "picture two", false,"pic_2"))
challenges.add(challenge_model("https://pic1.jpg", "picture two", false,"pic_3"))
challenges.add(challenge_model("https://pic1.jpg", "picture two", false,"pic_4"))
challenges.add(challenge_model("https://pic1.jpg", "picture two", false,"pic_5"))
val adapter = challenge_adapter(challenges)
recyclerView.adapter = adapter
adapter.notifyDataSetChanged()
根据上面的代码,关于不完全滚动,我的意思是我可以滚动看到三张图片,似乎就是它!但有时它会突然完全滚动并显示所有 5 张图片。
【问题讨论】:
-
你不需要水平滚动视图。甚至 Recyclerview 都会水平和垂直滚动
-
如果recyclerview本身也能正常工作,还需要水平滚动视图吗?
-
请参考以下网址,这可能会对您有所帮助stackoverflow.com/questions/34258496/…
-
请参考以下网址,这可能会对您有所帮助stackoverflow.com/questions/34258496/…
-
谢谢,尼克。当我删除 HorizontalScrollView 时,它可以正常工作!
标签: android kotlin scrollview