Android 中的 GridView 缩放和滚动速度缓慢
我正在创建一个派生自 GridView 的自定义视图。其中包含具有缩放和平移功能的自定义 ImageView。滚动和缩放功能缓慢。如果父视图是相同的自定义 ImageView 而不是 GridView,则它可以正常工作。我尝试这样做是因为我需要一个静态背景图像,中间有一个交互区域。缩放和滚动的实现类似于 这篇文章。我在此处上传了一个重现问题的测试项目。 OnCreate 方法的实现方式如下:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View myView1;
boolean sluggish = false;
if (sluggish) {
myView1 = new MyGridView(this);
}
else {
myView1 = new MyImageView(this);
}
setContentView(myView1);
}
如果将 sluggish 变量设置为 true,您会发现 ImageView 的效果要好得多。您知道为什么使用 GridView 会导致缩放和滚动无法使用吗?或者如何解决这个问题?
我没有在“静态”ImageView 中使用“动态”ImageView,因为我还没有找到如何将 ImageView 嵌入到另一个 ImageView 中。
提前致谢。
I'm creating a custom view derived from GridView. This contains a custom ImageView with zooming and panning functionality. Scroll and zoom functionality is sluggish. If the parent view is the same custom ImageView instead of a GridView it works perfectly. I'm trying to do this because I need a static background image with an interactive area at the center. Zoom and scroll are implemented similar to this article. I uploaded a test project reproducing the problem here. The OnCreate method is implemented like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View myView1;
boolean sluggish = false;
if (sluggish) {
myView1 = new MyGridView(this);
}
else {
myView1 = new MyImageView(this);
}
setContentView(myView1);
}
If you set the sluggish variable to true you'll see ImageView works much better for that. Do you have any idea why using GridView turns zoom and scroll unusable or how can this be solved?
I'm not using a "dynamic" ImageView into a "static" ImageView because I haven't found how to embed an ImageView into another ImageView.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,我发现的最简单、最容易的解决方案是使用自定义 FrameLayout:
其实现如下所示,并在我发布的第一个示例中使用 MyImageView 自定义控件。
我通过 Twitter 从 Lawrence D'Olivero 获得了替代解决方案建议。它包括对 View 进行子类化、对其进行缓存以及使用 OnDraw 事件来组成滚动图像在固定背景上作为他的演示 这里。
The simplest and easiest solution I found so far is using a custom FrameLayout:
Which is implemented as shown below and uses the MyImageView custom control in the first example I posted.
An alternative solution suggestion I got via twitter from Lawrence D'Olivero. It consists on subclassing View, caching it and using the OnDraw event for composing the scrolling image on a fixed background as his demo here.