java - 为什么我添加图像时出现延迟?

标签 java android lag

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

<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>

日志猫:

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

06-30 18:05:24.918: E/LocSvc_ApiV02(584): W/虚拟 loc_api_adapter_err LocApiV02::injectPosition(double, double, float):492]: 错误!状态 = eLOC_CLIENT_FAILURE_INVALID_PARAMETER,inject_pos_ind.status = 未知

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

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

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

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

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

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

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

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

最佳答案

您可以采取一些措施来解决滞后问题:

您可以缩小图片。

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

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

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

关于java - 为什么我添加图像时出现延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24495076/

相关文章:

java - 计算文本框填充的百分比

java - 过滤后,过滤器显示不正确的列表

android - 自定义Gradle任务挂起

Java 2D 游戏 "powered"by repaint();以一种奇怪的方式滞后

r - 在 R 中使用 dplyr 包 Lag 函数时有没有办法省略 NA?

java - 调用 setSupportActionBar 后 setBackgroundDrawable 出现 NullPointerException

Java:在 run 方法中使用的变量,在 for 循环中初始化的在 for 循环的语句中无法识别

具有自定义类的 BufferedReader 的 java.lang.StackOverflowError

android - 哪个是 Android 应用程序 Activity Change 的最佳方法

actionscript-3 - ActionScript:来自ByteArray的声音存在滞后