Android Activity 在 4.3 设备上运行缓慢 [英] Android Activity slow on 4.3 device

查看:20
本文介绍了Android Activity 在 4.3 设备上运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序,可以流式传输来自网络的视频.我有一个活动列出了视频,包括它们的图标、标题和状态(新更新).对于每一行,都有一个视频缩略图、视频标题,然后是一个新鲜"图标,表示它是新上传的.

I developed an app that would stream videos from the web. I have an activity that lists the videos including their icons, titles and status (newly updated). For every row, there is a thumbnail for the video, the video title, and then a "fresh" icon to indicate it's a new upload.

在模拟器中,这工作得比较好.在 2.3 和 4.0.3 HTC Evo 设备中,它运行良好.在 HTC One 4.3 设备上,此活动非常缓慢.单击列表中的一个项目,将您带到另一个活动,工作正常.除列表活动外,其他活动都可以.

In the emulator, this works relatively fine. In a 2.3 and 4.0.3 HTC Evo devices, it works great. On an HTC One 4.3 device, this activity is really slow. Clicking an item on the list, which takes you to another activity, works fine. Other activities are OK except the list activity.

这是我到目前为止所做的实验.我从 xml 中删除了新鲜"图标,效果很好.所以我认为它与这个图标有关.图像非常大(1000x900px),但仅以 50x50dp 渲染.我还没有尝试缩小此图像以查看性能.但如果是这个问题,老款HTC手机怎么能完美呈现呢.

Here's what I've experimented so far. I have removed the "fresh" icon from the xml, and it worked great. So I assumed it has something to do with this icon. The image is quite large (1000x900px) but only rendered in 50x50dp. I haven't tried downsizing this image to see the performance. But if this is the problem, how come the older HTC phones can render it perfectly.

与 HTC One 和旧款 HTC 手机的唯一区别是 HTC One 有一个操作栏,而旧款手机使用设备中的专用菜单键.

Only other difference from HTC One and the older HTC phones is that HTC One has an action bar and the older phones use the dedicated menu key in the device.

有没有办法在设备中运行应用程序时检查内存使用情况或进程,以了解它为何如此缓慢?

Is there a way to check the memory usage or processes while running an app in a device to see why it's taking so slow?

更新:我已将图像大小调整为 100x100 像素,而且速度肯定更快.但我仍然注意到有一些滞后.

UPDATE: I have resized the image to 100x100px, and it's definitely faster. But I still notice there is some lag.

这是该列表行的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="2dp"
    android:paddingTop="2dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true" />

    <ImageView
        android:id="@+id/status"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_toLeftOf="@id/status"
        android:layout_toRightOf="@id/icon" />
</RelativeLayout>

推荐答案

尝试开始方法分析(见图),然后启动你的活动,然后再次点击图中相同的按钮停止方法分析.Eclipse 将生成一个报告,您将在其中看到执行哪个方法需要多长时间.因此您可以找出导致延迟的方法.

Try to start method profiling (see picture), then launch your activity, then stop method profiling by hitting the same button in the picture again. Eclipse will generate a report where you will see which method takes what time to execute. Thus you can find out which method caused the delay.

这篇关于Android Activity 在 4.3 设备上运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆