今天因为要给banner的图片添加圆角,使用 Bitmap 转换圆角  用协程去切换线程 

在Debug中出现
ThreadException: Only the original thread that Created a view hierarchy can touch its views 

不debug时正常显示

猜测原因为: 协程在debug时,当前线程被断点阻塞,自动切换到其他线程中去了  导致不是原始的view历史记录线程操作显示View

解决办法为:

在与UI界面的控件交互的代码 加上

withContext(Dispatchers.Main){
  //你的 view 代码
  imageView.setImageBitmap(bitmap)
}

 

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2023-01-15
  • 2021-10-10
  • 2022-01-17
  • 2021-06-14
  • 2022-02-08
  • 2022-12-23
猜你喜欢
  • 2021-07-27
  • 2021-10-07
  • 2021-11-09
  • 2022-12-23
  • 2022-01-15
  • 2021-04-02
  • 2021-12-02
相关资源
相似解决方案