问题描述
编辑:
做了方法跟踪,每当我与紫色方形开关后,图上升了不少。当我用蓝色或绿色圆圈切换,它保持低:
After doing a method trace, whenever I switch with the purple square, the graph rises a lot. When I switch with a blue or green circle, it stays low:
下面是交换与紫色广场方法:
Here are the methods of the swap with the purple square:
我有交换两个按钮的应用程序。有一个红色的按钮,它被点击时,它选择从其他三个随机按钮,并互换。
I have an app which swaps two buttons. There is one red button, when it gets clicked, it picks a random button from the other three, and swaps.
我试图只是交换图像这样的一种方式。在onClickListener,我只是听了用红色按钮按钮点击。
I tried doing this one way by just swapping images. In the onClickListener, I only listened for clicks with buttons with the red button.
- 获取随机图像
- 请空白
- 查找红色按钮
- 给红色按钮的背景下,随机图像有(交换)
- 给随机图像(现为空)红色背景
如果这是令人困惑......离开它。但是:
If this is confusing...leave it. But:
每当我切换从一个更大的图片,以较小的图像,这个过程可能需要更长的时间。两个较小的图像之间的交换时,它的速度要快得多。我该如何解决这个问题。是否有一定的图像尺寸是最佳的为Android?
下面是布局code:
https://gist.github.com/anonymous/813883bce89606d2a82e
你可以在图像中看到的,它需要一个多(多!)更短的时间交换的背景图像的蓝色圆圈比紫色广场。为什么......?
As you can see in the image, it takes a much (MUCH!) shorter time swapping background images with the blue circle than the purple square. Why...?
为什么慢基于图像大小的方法(在这里我只是改变了影像和检查按钮带有红色图片)? 我应该用什么样的形象大小?
Why is the way (where I just change the images and check for a button with a red image) slower based on the image sizes? What image size should I use?
非常感谢您的时间
推荐答案
我没有你的问题的确切答案,但仅2建议:
I dont have the exact answer for your question but just 2 recommendations:
1)先绘制之前,请确保您缩放图像。
1) Make sure you scale the image first before drawing.
2)使用的RelativeLayout使你的ViewGroup来衡量你的孩子,而不是一两次。所以请确保您不做任何触发click事件重新布局
2) Using RelativeLayout causes your ViewGroup to measure your children twice instead of one. So Make sure that you dont do any that trigger re-layout on click events
3)我建议你把这些视图在GridView或网格布局,然后当你需要换你的意见,只要将您的视图的位置在一个数据(数组,例如),并调用notifyDataSetChanged() ;
希望这有助于
3) I would suggest that you put these View in a GridView or GridLayout and then when you need to swap your views, just swap the positions of your view in an data (Array, for example), and call notifyDataSetChanged();Hope this help
这篇关于摄像载入时间太长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!