诊断慢速渲染片段

时间:2013-11-30 17:51:04

标签: android android-fragments

在手机上运行时,我的应用会将片段交换为主要活动。在特定的常用片段上使用FragmentTransaction.replace()方法时,我会在屏幕重绘之前看到onResume()后大约2秒的延迟。编舞者每次抱怨100多个错过的帧。有一个GridView和一些按钮。适配器和数据库访问似乎在延迟之前快速处理所有杂务。我最好的猜测布局可能效率低下,但我不知道怎么做。诊断和优化是否有任何技巧?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"
    android:baselineAligned="false"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/buttonBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/content_background"
        android:layout_marginTop="10dp"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/ivFilters"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:contentDescription="@string/cd"
            android:background="@drawable/blank" 
            />

        <ImageView
            android:id="@+id/ivReference"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:contentDescription="@string/cd"
            android:background="@drawable/blank" />

        <ImageView
            android:id="@+id/ivCabinet"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:contentDescription="@string/cd"
            android:background="@drawable/blank" />

        <EditText
            android:id="@+id/etSearch"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:background="@drawable/et_search"
            android:drawableLeft="@android:drawable/ic_menu_search"
            android:hint="@string/search" 
            android:singleLine = "true"
            />
    </LinearLayout>

    <TextView
        android:id="@+id/tvFilterName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/content_background"
        android:text="@string/all_recipes"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:textColor="@color/white"
        android:textSize="30sp" />

        <GridView
            android:id="@+id/gridDrinks"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:numColumns="1"
            android:listSelector="@android:color/transparent"
            />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

  

编舞者每次抱怨100多个错过的帧

然后问题出在您的Java代码中,在那里您将占用主应用程序线程。

  

诊断和优化是否有任何技巧?

从启用StrictMode开始,因为我的猜测是你在主应用程序线程上进行数据库I / O.

然后,如果没有指出任何问题,请使用Traceview确切地确定您的时间花在哪里。

可能性,它与您的布局资源无关。

相关问题