From c86e44f264af254f9bf5b50253f15c0d4c87197b Mon Sep 17 00:00:00 2001 From: dongliang Date: Mon, 27 Apr 2026 18:42:50 +0930 Subject: [PATCH] =?UTF-8?q?fix:=20ViewPager2=20=E5=AD=90=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20match=5Fparent=20LayoutParams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ViewPager2 要求子页面必须填满,inflate 时未指定 parent 导致 LayoutParams 丢失。 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../java/com/xiaoqu/watch/ui/home/HomePagerAdapter.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/xiaoqu/watch/ui/home/HomePagerAdapter.kt b/app/src/main/java/com/xiaoqu/watch/ui/home/HomePagerAdapter.kt index 9d8cc81..9db29dd 100644 --- a/app/src/main/java/com/xiaoqu/watch/ui/home/HomePagerAdapter.kt +++ b/app/src/main/java/com/xiaoqu/watch/ui/home/HomePagerAdapter.kt @@ -16,7 +16,13 @@ class HomePagerAdapter( class PageViewHolder(val view: View) : RecyclerView.ViewHolder(view) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder { - return PageViewHolder(pages[viewType]) + val view = pages[viewType] + // ViewPager2 要求子页面必须 match_parent + view.layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + return PageViewHolder(view) } override fun onBindViewHolder(holder: PageViewHolder, position: Int) {