Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同一类型的多个 fragment 实例的 binding.view 引用错位问题 #36

Open
DQSecret opened this issue Sep 5, 2022 · 2 comments

Comments

@DQSecret
Copy link

DQSecret commented Sep 5, 2022

代码结构:
Activity -> 上下两个 Fragment (同一个类型的,2个实例)

具体使用:

class ImageAdFragment : AdFragment(R.layout.fragment_image_ad) {

    private val binding by viewbind<FragmentImageAdBinding>()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Utils.log("加载图片${model.url}")
        Glide.with(binding.ivImg.context).asBitmap().load(File(model.url)).into(binding.ivImg)
    }
}

导致第二个 fragment 的图片,展示到了第一个 fragment 里的 ImageView 上,
然后,第二个 Fragment 显示空白...

@hi-dhl
Copy link
Owner

hi-dhl commented Sep 7, 2022

收到,我本地复现一下

@hi-dhl
Copy link
Owner

hi-dhl commented Oct 12, 2022

很抱歉,最近一直在忙,现在才看这个问题, 我按照你说的,写了一个示例,并没有出现你说的问题

val fragment1 = NestedFragment1()
fragment1.resId = R.drawable.avatar
val fragment2 = NestedFragment1()
fragment2.resId = R.drawable.logo
supportFragmentManager.beginTransaction()
.add(R.id.fragment1, fragment1)
.add(R.id.fragment2, fragment2)
.commit()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants