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

如果XML中ImageView并不是在第一层第一个所导致的崩溃问题 #49

Open
GitJoBo opened this issue Aug 7, 2023 · 1 comment

Comments

@GitJoBo
Copy link

GitJoBo commented Aug 7, 2023

PhotoViewer的findImageView函数
private fun findImageView(group: ViewGroup): ImageView? {
for (i in 0 until group.childCount) {
return when {
group.getChildAt(i) is ImageView -> group.getChildAt(i) as ImageView
group.getChildAt(i) is ViewGroup -> findImageView(group.getChildAt(i) as ViewGroup)
else -> throw RuntimeException("未找到ImageView")
}
}
return null
}

只会判断第一个view,for循环是没用的

@GitJoBo
Copy link
Author

GitJoBo commented Aug 7, 2023

这是修复后可用的函数
private fun findImageView(group: ViewGroup): ImageView? {
for (i in 0 until group.childCount) {
val child = group.getChildAt(i)
if (child is ImageView) {
return child
} else if (child is ViewGroup) {
val result = findImageView(child)
if (result != null) {
return result
}
}
}
throw RuntimeException("未找到ImageView")
}

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

1 participant