3
我正在嘗試爲我的應用程序構建啓動屏幕。當我嘗試更改我的imagesview屬性並設置動畫時,我收到一個錯誤。只有創建視圖層次結構的原始線程才能觸及其視圖
我已經測試了runonuithread和Hadler,但在這2種情況下沒有任何錯誤,屏幕上也沒有顯示任何內容,並且延遲後(正是我在代碼中指定的內容)程序活動切換到下一個活動我的代碼:
@Override
public void run(){
try {
TranslateAnimation moveLefttoRight = new TranslateAnimation(500, 0, 0, 0);
moveLefttoRight.setDuration(5000);
moveLefttoRight.setFillAfter(true);
im.startAnimation(moveLefttoRight);//im is an image view
SystemClock.sleep(6000);
TranslateAnimation moveRighttoLeft = new TranslateAnimation(0, 100, 0, 0);
moveRighttoLeft.setDuration(1000);
moveRighttoLeft.setFillAfter(true);
im.startAnimation(moveRighttoLeft);
SystemClock.sleep(6000);
ScaleAnimation scale = new ScaleAnimation(0.3f, 1f, 0.3f, 1f,
ScaleAnimation.RELATIVE_TO_SELF, 0f,
ScaleAnimation.RELATIVE_TO_SELF, 0f);
scale.setDuration(1000);
scale.setFillAfter(true);
// Wait given period of time or exit on touch
sig.startAnimation(scale);//sig is an image view
SystemClock.sleep(2000);
}
我該如何解決這個奇怪的錯誤?
你正試圖使鑑於UI線程的出方的變化......你必須動畫UI線程內您的ImageView不是在你的線程 –
我嘗試UI線程有沒有錯誤,但只是告訴我一個黑屏屏幕inested我的圖像 –
然後,您必須檢查您的代碼或發佈您的代碼尋求幫助...並始終記住,只有UI線程可以在視圖中進行更改 –