本文介绍了低迷的缩放和滚动与GridView控件Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的GridView控件派生的自定义视图。这包含一个自定义的ImageView与缩放和平移功能。滚动和缩放功能呆滞。如果父视图是相同的自定义ImageView的,而不是一个GridView它完美的作品。我想这样做,因为我需要一个静态背景图像为中心的互动区。缩放和滚动实施类似这篇文章。我上传了一个测试项目这里重现问题。该onCreate方法是这样实现的:

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);
}

如果您设置的呆滞的变量设置为true,你会看到ImageView的效果要为好。你有任何想法,为什么使用的GridView变成缩放和滚动无法使用或如何加以解决?

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?

我不使用一个动态的ImageView成静态的ImageView,因为我还没有找到如何嵌入一个ImageView的到另一个ImageView的。

I'm not using a "dynamic" ImageView into a "static" ImageView because I haven't found how to embed an ImageView into another ImageView.

在此先感谢。

推荐答案

我发现迄今使用自定义的FrameLayout最简单,最简单的方法:

The simplest and easiest solution I found so far is using a custom FrameLayout:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View myView1 = new MyFrameLayout(this);

    setContentView(myView1);
}

哪个被实现如下所示,并使用在我张贴的第一例中的MyImageView定制控制

Which is implemented as shown below and uses the MyImageView custom control in the first example I posted.

public class MyFrameLayout extends FrameLayout {

    public MyFrameLayout(Context context) {
        super(context);

        MyImageView i1 = new MyImageView(context);

        this.addView(i1);


        MyImageView i2 = new MyImageView(context);

        LayoutParams lp = new LayoutParams(300, 300);
        lp.leftMargin = 100;
        lp.topMargin = 100;
        lp.gravity = 0;

        this.addView(i2, lp);
    }
}

这是另一种解决方案建议,我通过Twitter从劳伦斯D'Olivero 了。它包括在子类视图,其高速缓存和使用的OnDraw事件以构成滚动图片在一个固定的背景,他的演示这里

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.

这篇关于低迷的缩放和滚动与GridView控件Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:15