2016-06-18 15 views
0

ich meine erste App bauen, aber ein paar Layout Sachen ein DrawerLayout nach der Zugabe um genau zu sein fing es an mir, einen Fehler zu geben:Android Haupt-Thread zu viel Arbeit

I/Choreographer: Skipped 126 frames! The application may be doing too much work on its main thread

Das hier ist mein Layout-Code :

<!-- The main content view --> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 




<!-- ładowanie toolbara --> 
<include 
layout="@layout/tool_bar" 

/> 
<include 
layout="@layout/twoja_strona" 

/> 
<RelativeLayout 


    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:layout="http://schemas.android.com/apk/res-auto" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="pl.webimpuls.wicms.MainActivity" 
    android:background="#e7e7e7"> 




<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:columnCount="2" 
    android:rowCount="4" 
    android:id="@+id/gridLayout"> 

     <RelativeLayout android:layout_width="fill_parent" 
      android:orientation="horizontal"> 
     <RelativeLayout 
     android:layout_width="160dp" 
     android:layout_height="100dp" 
     android:layout_row="1" 
     android:layout_column="1" 
      android:background="@color/background_material_light" 
      android:layout_marginRight="5dp" 
      android:layout_gravity="center|left" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="0dp" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="0dp" 
      android:id="@+id/dodaj_wpis" 
      android:clickable="true" 
      android:onClick="dodajaaktualnosc"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView2" 
       android:src="@mipmap/dodaj_wpis" 
       android:layout_above="@+id/textView" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentTop="true" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
         android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Dodaj Wpis" 
       android:id="@+id/textView" 
       android:textAlignment="center" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="160dp" 
      android:layout_height="100dp" 
      android:layout_row="1" 
      android:layout_column="0" 
      android:background="@color/background_material_light" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:id="@+id/lista_aktualnosci" 
      android:clickable="true" 
      android:onClick="czytajaktualnosc"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView3" 
       android:src="@mipmap/lista_aktualnosci" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentTop="true" 
       android:layout_above="@+id/textView2" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Lista Aktualności" 
       android:id="@+id/textView2" 
       android:textAlignment="center" 
       android:singleLine="true" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 
     </RelativeLayout> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_row="2" 
      android:layout_column="0" 
      android:layout_marginBottom="10dp" 
      android:background="@color/background_material_light" 
      android:layout_marginTop="10dp" 
      android:id="@+id/twoje_leady" 
      android:clickable="true" 
      android:onClick="leady"> 

      <ImageView 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView4" 
       android:src="@mipmap/twoje_leady" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginLeft="30dp" 
       android:layout_alignParentBottom="true" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Twoje Leady" 
       android:id="@+id/textView3" 
       android:textAlignment="center" 
       android:layout_centerVertical="true" 
       android:layout_toRightOf="@+id/imageView4" 
       android:layout_toEndOf="@+id/imageView4" 
       android:layout_marginLeft="46dp" 
       android:layout_marginStart="46dp" /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_row="3" 
      android:layout_column="0" 
      android:background="@color/background_material_light" 
      android:id="@+id/otworz_strone" 
      android:clickable="true" 
      android:onClick="otworzstrone"> 

      <ImageView 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView5" 
       android:src="@mipmap/otworz_strone" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginLeft="30dp" 
       android:layout_alignParentBottom="true" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Otwórz Stronę" 
       android:id="@+id/textView4" 
       android:textAlignment="center" 
       android:layout_centerVertical="true" 
       android:layout_toRightOf="@+id/imageView5" 
       android:layout_toEndOf="@+id/imageView5" 
       android:layout_marginLeft="46dp" 
       android:layout_marginStart="46dp" /> 

     </RelativeLayout> 

    </GridLayout> 
<include 
    layout="@layout/stopka" 
    android:layout_alignParentBottom="true" 
    android:layout_height="50dp" 
    android:layout_width="wrap_content"> 

</include> 
</RelativeLayout> 

</LinearLayout> 

<include 
layout="@layout/menu_wysuwajace"></include> 

</android.support.v4.widget.DrawerLayout> 

Bitte ich muss wissen, was los ist.

Hier ist mein Java ist es nicht so massiv, denke ich. Wie könnte ich es auf async laufen lassen?

package pl.webimpuls.wicms; 

import android.content.Intent; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.Toolbar; 
import android.view.MotionEvent; 
import android.view.View; 
import android.widget.RelativeLayout; 
import com.crashlytics.android.Crashlytics; 
import io.fabric.sdk.android.Fabric; 

public class MainActivity extends AppCompatActivity { 

private Toolbar toolbar; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Fabric.with(this, new Crashlytics()); 
    setContentView(R.layout.activity_main); 

    RelativeLayout dw = (RelativeLayout)findViewById(R.id.dodaj_wpis); 



} 


public void dodajaaktualnosc(View view) 
{ 
    Intent dodaj = new Intent(MainActivity.this, aktualnosci_dodaj.class); 
    startActivity(dodaj); 
} 

public void czytajaktualnosc(View view) 
{ 
    Intent czytaj = new Intent(MainActivity.this, aktualnosci.class); 
    startActivity(czytaj); 
} 
public void leady(View view) 
{ 
    Intent leady = new Intent(MainActivity.this, aktualnosci.class); 
    startActivity(leady); 
} 
public void otworzstrone(View view) 
{ 
    Intent otworzurl = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.webimpuls.pl")); 
    startActivity(otworzurl); 
} 

}

+0

Post logcat Nachricht (dh die volle Fehler verwenden können Nachricht, die Sie haben) –

+0

I/Choreograph: übersprungen 126 Rahmen! Die Anwendung führt möglicherweise zu viel Arbeit an ihrem Hauptthread aus. Und bei der Verwendung der Navigationsschublade ist alles nachlässig – Fadlan

+2

Es gibt bereits eine Antwort auf Ihre Frage [hier] (http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on) -its-main-thread? rq = 1) –

Antwort

0

können Sie führen lange Aufgaben auf separaten Arbeitsthread ausgeführt wird, sofern Sie asyntasks, Volley-Bibliothek, nachzurüsten Bibliothek usw. für Netzwerk ruft