活动跳过100帧?花了太长时间出现?

时间:2015-07-17 08:31:05

标签: android android-activity frame

活动耗时太长而无法出现。我不知道为什么,它的布局很简单,但每次都会跳过500帧以上。我没有做任何繁重的工作,它是如此愚蠢我只设置主布局文件。

package zafus.pointme;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class CreateEventActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_event);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_create_event, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

这是活动的layout.xml。

<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" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="zafus.pointme.CreateEventActivity">

    <TextView android:id="@+id/create_event_fromal" android:text="Create new event and send invites to your friends and family." android:textSize="20sp" android:textColor="#0099cc" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />



    <TextView
       android:id="@+id/recepient"
        android:layout_below="@+id/create_event_fromal"
       android:layout_marginTop="15dp"
        android:layout_alignParentLeft="true"
       android:layout_width="wrap_content"
       android:text="Send To: "
       android:textColor="#0099cc"
       android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/recepient_contact"
           android:layout_width="fill_parent"
        android:layout_below="@+id/create_event_fromal"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@+id/recepient"
        android:hint="Tap to add recepients"
        android:layout_alignBaseline="@+id/recepient"
        android:layout_height="wrap_content" />
    <LinearLayout
        android:layout_below="@+id/recepient_contact"
        android:layout_marginTop="10dp"
        android:id="@+id/create_event_image"
        android:layout_alignParentLeft="true"
        android:orientation="vertical"

        android:gravity="bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/event_picture"
            android:layout_width="100dp"
            android:scaleType="fitXY"
            android:src="@drawable/arrow_use"
            android:layout_height="100dp" />

        <TextView
            android:textColor="#0099cc"
            android:layout_width="100dp"
            android:text="Featured Image"
            android:layout_height="wrap_content" />

        </LinearLayout>

        <EditText
            android:layout_width="fill_parent"
            android:id="@+id/title"
            android:hint="Event Title"
            android:layout_height="wrap_content"
            android:layout_below="@+id/recepient"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="10dp"
            android:layout_toEndOf="@+id/create_event_image"
            android:layout_toRightOf="@+id/create_event_image" />




        <TextView
            android:id="@+id/when"
            android:layout_width="wrap_content"
            android:textColor="#0099cc"
            android:text="When: "

            android:layout_marginBottom="21dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/create_event_image"
            android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/comment"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_below="@+id/create_event_image"
        android:layout_marginTop="4dp"
        android:hint="Comment if any"
         />

    <CalendarView
        android:id="@+id/datepicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginBottom="4dp"
        android:layout_above="@+id/comment"
        android:layout_toRightOf="@+id/when"
        android:layout_toEndOf="@+id/when">
      </CalendarView>

</RelativeLayout>

这就是logcat所说的:

07-17 13:15:18.001      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.001      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.003      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.003      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.004      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.004      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:15:18.088      637-637/zafus.pointme I/Choreographer﹕ Skipped 372 frames!  The application may be doing too much work on its main thread.
07-17 13:15:26.544      637-652/zafus.pointme I/art﹕ Background partial concurrent mark sweep GC freed 212268(7MB) AllocSpace objects, 0(0B) LOS objects, 36% free, 28MB/44MB, paused 3.387ms total 136.810ms
07-17 13:15:41.899      637-647/zafus.pointme W/art﹕ Suspending all threads took: 19.104ms
07-17 13:15:41.912      637-652/zafus.pointme I/art﹕ Background sticky concurrent mark sweep GC freed 414866(14MB) AllocSpace objects, 0(0B) LOS objects, 21% free, 29MB/37MB, paused 2.258ms total 132.690ms
07-17 13:16:45.033      637-647/zafus.pointme W/art﹕ Suspending all threads took: 7.965ms
07-17 13:17:09.585      637-647/zafus.pointme W/art﹕ Suspending all threads took: 6.500ms
07-17 13:17:19.262      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.262      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.262      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.262      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.265      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.265      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.293      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.293      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.293      637-637/zafus.pointme D/BubblePopupHelper﹕ isShowingBubblePopup : false
07-17 13:17:19.297      637-637/zafus.pointme I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@7dca64b time:14405839

2 个答案:

答案 0 :(得分:3)

您可以使用Android Studio中的探查器找到速度问题的原因: enter image description here

答案 1 :(得分:1)

加载CalendarView时似乎有一些奇怪的行为。我最近通过设置DatePickerandroid:calendarViewShown="false"中处理了该问题,这可以很好地加快速度。也许你也可以尝试一下。

编辑:SO有几个关于CalendarViews效果的问题,例如CalendarView takes much time for displaying