我正在构建我的第一个应用,但在添加了一些布局后,DrawerLayout
确切地说它开始给我一个错误:
I / Choreographer:跳过126帧!应用程序可能在其主线程上做了太多工作
这是我的布局代码:
<!-- 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>
我需要知道发生了什么。
这是我的java,我认为它不是那么大。 我怎么能在异步上运行它?
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 :(得分:0)
您可以在单独的工作线程上运行长时间运行的任务,以便您可以使用asyntasks,volley Library,改造库等进行网络调用