会出现这个问题是因为点击之后未等动画结束就立即开始刷新视图,因此等结束之后再加载界面即可
添加监听:
var isDrawerClosed = true
drawer_layout.addDrawerListener(object : DrawerLayout.DrawerListener{
override fun onDrawerClosed(drawerView: View) {
Log.d("MyMain", "onDrawerClosed")
isDrawerClosed = true
}
override fun onDrawerOpened(drawerView: View) {
Log.d("MyMain", "onDrawerOpened")
isDrawerClosed = false
}
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {}
override fun onDrawerStateChanged(newState: Int) {}
})
之后在待加载位置新建线程监听isDrawerClosed
变化即可。
Thread{
while(xxxWeakReference?.get()?.isDrawerClosed != true) sleep(233)
....//开始加载
}.start()