嵌入的ListView里面图库 [英] Embedding ListView inside Gallery

查看:128
本文介绍了嵌入的ListView里面图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的目标是实现一个廊其适配器返回列表视图(换句话说,垂直滚动嵌入在水平滚动廊列表视图)。它有点工作后的排​​序工作,但在尝试水平滚动时,在ListView看起来非常紧张不安,好像有一定的粘性,它为中心。我还没有发现这种行为与嵌入在画廊的任何其他类型的视图。

The goal is to implement a Gallery whose adapter returns ListViews (in other words, vertically scrolling ListViews embedded in a horizontally scrolling Gallery). It sort of works after a bit of work, but when attempting to scroll horizontally, the ListView looks very jittery, like there is some stickiness to it being centered. I have not observed this kind of behavior with any other type of View embedded in a Gallery.

下面是我曾尝试:

起初,我发现,在ListView压扁触摸事件,所以在画廊的姿态监听器永远不会被解雇了。

Initially, I found that the ListView squashed touch events, so the gesture listener on the Gallery never gets fired.

因此​​,在活动的onCreate()方法中,我创建了一个GestureDetector:

So in the onCreate() method of the Activity, I created a GestureDetector:

galleryGestureDetector =新GestureDetector(这一点,图库);

然后,画廊适配器的getView()方法中,后的ListView已经膨胀和配置,我有一些code是这样的:

Then, inside the getView() method of the Gallery adapter, after the ListView has been inflated and configured, I have some code like this:

listView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        galleryGestureDetector.onTouchEvent(event);
        return true;
    }
});

在这种情况下,我甚至去返回true从OnTouchListener确保列表视图的的onTouchEvent()方法从来没有真正所谓的极端一步。会发生同样的风声鹤唳的行为。这样一来,我想我可以排除竞争的onTouchEvent()实现这两种观点之间。

In this case I have even gone to the extreme step of returning true from the OnTouchListener to ensure that the onTouchEvent() method of the listView is never actually called. The same jittery behavior occurs. As a result, I think I can rule out competing onTouchEvent() implementations between the two views.

我试图通过延长画廊的触摸矩形,包括ListView控件,然后强迫的ListView委托给它滥用TouchDelegate理念为好,但这是徒劳的努力也是如此。

I tried abusing the TouchDelegate concept as well by extending the Gallery's touch rectangle to include the ListView and then forcing the ListView to delegate to it, but this was a futile effort as well.

我会扔了我的手,说,这是不可能的现在,但社交网络应用程序,与DroidX包以某种方式完成了!

I would throw up my hands and say it isn't possible currently, but the Social Networking app that packs with the DroidX somehow accomplishes it!

推荐答案

的问题是,ListView中从图库截取的触摸事件,然后改变视图位置本身。这是什么导致了来回抖动的效果,我看的时候我用的部件不变。我认为这是画廊部件的错误,但在此期间,它可以固定通过继承画廊是这样的:

The problem is that ListView is intercepting touch events from the Gallery and then altering the view position itself. This is what leads to the back and forth jittering effect that I see when I use the widgets as is. I consider this a bug in the Gallery widget, but in the meantime it can be fixed by subclassing Gallery like this:

public class BetterGallery extends Gallery {
private boolean scrollingHorizontally = false;

public BetterGallery(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public BetterGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public BetterGallery(Context context) {
    super(context);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    super.onInterceptTouchEvent(ev);
    return scrollingHorizontally;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    scrollingHorizontally = true;
    return super.onScroll(e1, e2, distanceX, distanceY);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch(event.getAction()) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        scrollingHorizontally = false;
    }

    return super.onTouchEvent(event);
}

}

如果你的地方画廊使用BetterGallery,整个事情的作品就好了!

If you use BetterGallery in place of Gallery, the whole thing works just fine!

这篇关于嵌入的ListView里面图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆