我开发了一个可以从网络传输视频的应用程序。我有一个活动列出了视频,包括它们的图标、标题和状态(新更新)。每行都有一个视频缩略图、视频标题,然后有一个“新鲜”图标来指示它是新上传的。
在模拟器中,这工作得相当好。在 2.3 和 4.0.3 HTC Evo 设备中,它运行良好。在 HTC One 4.3 设备上,此活动非常慢。单击列表中的某个项目可以将您带到另一个活动,效果很好。除了列表活动之外,其他活动都可以。
这是我到目前为止所做的实验。我已经从 xml 中删除了“新鲜”图标,效果很好。所以我认为这与这个图标有关。图像相当大 (1000x900px),但仅以 50x50dp 渲染。我还没有尝试缩小该图像的尺寸来查看性能。但如果这就是问题所在,那么旧款 HTC 手机为何能够完美呈现它。
与 HTC One 和旧款 HTC 手机的唯一区别是 HTC One 有操作栏,而旧款手机使用设备中的专用菜单键。
有没有办法在设备中运行应用程序时检查内存使用情况或进程,以了解为什么速度这么慢?
更新:
我已将图像大小调整为 100x100px,而且速度肯定更快。但我仍然注意到有一些滞后。
这是该列表行的布局:
<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 将生成一个报告,您可以在其中看到哪个方法执行需要多长时间。这样您就可以找出导致延迟的方法。
![enter image description here](https://i.stack.imgur.com/f0L6K.jpg)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)