2015-12-16 28 views
0

我是Android的新編程,我在ADT中有一個非常簡單的例子,我每幀只有2個ImageView在一個FrameLayout中,但是當我用我的手機測試它的應用程序真的很慢,因爲它沒有任何邏輯原因,我沒有碰到java文件夾。Android - 該應用程序可能在其主線程上做了太多的工作

這是我在

12-16 16:17:43.261 18238-18238/com.example.brank.acocinapp I/Choreographer: Skipped 64 frames! The application may be doing too much work on its main thread. 
12-16 16:17:44.781 18238-18248/com.example.brank.acocinapp W/art: Suspending all threads took: 26.044ms 
12-16 16:17:44.831 18238-18238/com.example.brank.acocinapp W/PathParser: Points are too far apart 4.000000596046461 

得到錯誤這是我content_main.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.brank.acocinapp.MainActivity"> 

    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/frameLayout2" 
     android:layout_alignParentBottom="true"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/imageView3" 
      android:adjustViewBounds="true" 
      android:src="@drawable/home2" /> 
    </FrameLayout> 


    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/frameLayout" 
     android:layout_alignParentTop="true"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/imageView2" 
      android:src="@drawable/home1" 
      android:adjustViewBounds="true"/> 

    </FrameLayout> 


</RelativeLayout> 

的XML我不得不提,如果我評論兩者之一的FrameLayout問題犯規存在。提前致謝。

編輯:我也把2個圖像中的文件夾可繪製(我不知道這是否會影響),但我在一個教程,我已經把在子文件夾中的圖像繪製對象看到(MDPI,華電國際,xhdpi ,xxhdpi)的事情是,這個子文件夾不存在,所以我粘貼我的圖像繪製。

+0

它有可能是你的圖像非常大?你可以創建一個文件夾** drawable-nodpi **來放置你的圖像。 –

+0

使用AsyncTasks和線程將有所幫助。如果所需的可繪製文件夾不存在,只需製作它們即可。 –

+0

@JoseAngelManeiro我的圖像是1024x768 PNG,大小是1.40M,你認爲它是一個應用程序的大圖像?建議的分辨率和尺寸應該是多少? –

回答

3

好的可能是因爲操作系統試圖對圖像進行大量處理,您可能會選擇高分辨率圖像。你可以做的是嘗試創建圖像的多個分辨率(mdpi,hdpi,xhdpi,xxhdpi)。您可以將圖像的標準大小作爲mdpi,並分別以hdpi,xhdpi,xxhdpi的比例1.5,2,3增加大小。當你把這些圖像放在可繪製文件夾中時,如果你沒有他們自己創建它們。有時候這可能會導致Android中的OOM。一篇文章explaining吧。

+0

是的,我看到了一些關於hdpi,xhdpi,xxhdpi的事情是這些文件夾不存在。我應該在「可繪製」文件夾中創建這些文件夾嗎? –

+2

是創建文件夾像drawable-mdpi,drawable-hdpi,drawable-xhdpi,drawable-xxhdpi – harshitpthk

+0

現在我得到下一個錯誤:「Could not'resource resource @ drawable/home2」我把圖像放在drawable-mdpi –

0

您應該檢查文檔AsyncTaskThread
還爲Main Threads and Worker Threads

非常指引說明正在發生的事情是,你在主線程中執行大量消耗CPU資源的過程中可能會導致您的主UI線程掛起。解決這個問題的方法是在工作線程中完成整個圖像處理,並保持僅用於UI交互的主線程。

+0

好吧,我看看,它可能是一個解決方案,使圖像處理的線程,但我怎麼能做到這一點?我爲測試它所做的事情是創建一個執行下一句話的線程:setContentView(R.layout。activity_main);在MainActivity中的OnCreate()方法中,但是當我在手機中測試它時,它會強制關閉。什麼是使圖像處理的句子? –

+0

工作線程不應觸及主UI,因此您無法在工作線程中設置ContentView。 AsyncTask的實現是重寫doInBackground()方法,在該方法中,您將放置所有圖像處理過程並覆蓋將用於更新主UI線程的onPostExecute()方法 – DimLek

相關問題