UI를로드하고 싶으면 사용자가 UI를 볼 수있는 다른 코드를 볼 수 있습니다. UI 스레드에서 해당 코드를 실행하고 싶습니다. 내가이 일을 얻을 수UI가 표시된 후 안드로이드 실행 메소드/코드가 표시됩니다.
onCreate(){
setContentView(R.layout.mylayout);//myLayout starts with a blue background
myLayout = (LinearLayout)....
myLayout.setBackgroundColor(red);
}
onViewDisplayed(){
//myLayout is visible and shows a red background while the UI thread is blocked by Thread.sleep()
Thread.sleep(5000);
myLayout.setBackgroundColor(yellow);
}
한 가지 방법은이 일을하는 것입니다 :
onCreate(){
setContentView(R.layout.mylayout);//myLayout starts with a blue background
myLayout = (LinearLayout)....
myLayout.setBackgroundColor(red);
handler.postDelayed(runnable,1000);//runnable calls onViewDisplayed() above
}
이 방법은 내가 원하는 것이 아니다,하지만. postDelayed를 100ms로 변경하면 myLayout
은 Thread.sleep(5000)
앞에 빨간색 배경이 표시되지 않으므로 노란색 배경이 보입니다.
가능한 경우 지연을 지정하지 않고 레이아웃을 표시 한 후 보장 된 실행으로 어떻게이 작업을 수행 할 수 있습니까?
작동하는 것처럼 보입니다. 나는 내일 그것을 시험 할 것이다. – Jakar