Android Activity slow on 4.3 device(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 设备上运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Activity 在 4.3 设备上运行缓慢
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01