当我添加图像时为什么会有滞后?

时间:2014-06-30 16:48:02

标签: java android lag

我最近一直遇到滞后,当我运行我的程序时,我的一个活动有7个图像,我计划添加更多但是当我开始向下滚动整个事情滞后时,我不知道它是否因为动作我隐藏在xml中的栏(我隐藏它因为我不知道如何从活动中删除它),我希望你们能告诉我如何解决这个问题(滞后问题)。

<ScrollView 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"
tools:context=".EX" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="688dp" >

    <ImageView
        android:id="@+id/border"
        android:layout_width="wrap_content"
        android:layout_height="7dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/greenborder" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView2"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="50dp"
        android:clickable="true"
        android:src="@drawable/ss" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginRight="40dp"
        android:clickable="true"
        android:src="@drawable/cht" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="28dp"
        android:clickable="true"
        android:src="@drawable/ags" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignLeft="@+id/imageView3"
        android:layout_alignTop="@+id/imageView4"
        android:clickable="true"
        android:src="@drawable/as" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignLeft="@+id/imageView4"
        android:layout_below="@+id/imageView4"
        android:layout_marginTop="27dp"
        android:clickable="true"
        android:src="@drawable/ly" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignLeft="@+id/imageView5"
        android:layout_alignTop="@+id/imageView6"
        android:clickable="true"
        android:src="@drawable/co" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageView3"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="9dp"
        android:text="Select a category:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignLeft="@+id/imageView6"
        android:layout_below="@+id/imageView6"
        android:layout_marginTop="27dp"
        android:clickable="true"
        android:src="@drawable/fy" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView8"
        android:layout_alignLeft="@+id/imageView7"
        android:layout_alignRight="@+id/imageView7"
        android:text="More available soon"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

</ScrollView>

logcat:

06-30 18:05:24.908:E / LocSvc_IzatApiV02(584):W / virtual int izat_core :: IzatApiV02 :: injectLocation(GpsExtLocation):665]:错误!注入位置失败

06-30 18:05:24.918:E / LocSvc_ApiV02(584):W / virtual loc_api_adapter_err LocApiV02 :: injectPosition(double,double,float):492]:错误! status = eLOC_CLIENT_FAILURE_INVALID_PARAMETER,inject_pos_ind.status = UNKNOWN

06-30 18:05:24.968:I / GCoreUlr(6145):成功插入位置

06-30 18:05:24.968:I / GCoreUlr(6145):未调用LocationReportingService,hasMoved:false,已用过的millis:2176457,请求:电话

06-30 18:05:28.802:I / Choreographer(8748):跳过39帧!应用程序可能在其主线程上做了太多工作。

06-30 18:05:29.483:I / Choreographer(8748):跳过40帧!应用程序可能在其主线程上做了太多工作。

06-30 18:05:30.154:I / Choreographer(8748):跳过39帧!应用程序可能在其主线程上做了太多工作。

06-30 18:05:30.834:I / Choreographer(8748):跳过40帧!应用程序可能在其主线程上做了太多工作。

06-30 18:05:31.495:I / Choreographer(8748):跳过39帧!应用程序可能在其主线程上做了太多工作。

06-30 18:05:32.166:I / Choreographer(8748):跳过39帧!应用程序可能在其主线程上做了太多工作。

1 个答案:

答案 0 :(得分:1)

您可以针对延迟问题采取某些措施:

您可以缩小图片范围。

  1. 为此,我强烈建议您阅读此Loading Large Bitmaps Efficiently

  2. 在res文件夹中创建一个名为drawable-nodpi的新文件夹,并将所有png(图片)资源移到那里!

  3. 将图像大小从2048 x 2048调整为较低分辨率。