二维滚动......需要反馈的建议 [英] Two dimensional scrolling... a suggestion that needs feedback

查看:128
本文介绍了二维滚动......需要反馈的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然花费的时间量丰富google搜索一个相对简单的解决我的问题,我发现这个作为二维滚动的解决方案。我有AA horizo​​ntalscrollview嵌套在一个滚动视图。我在几个方面拨弄着这一点,是不成功的在做任何事情的功能。有没有人对如何使这样的工作理念什么想法?

While spending a copious amount of time googling for a relatively simple solution to my problem I found this as a solution for two-dimensional scrolling. I have a a horizontalscrollview nested in a scrollview. I fiddled with this in a few ways and was unsuccessful in making anything functional. Does anyone have any ideas on how to make a concept like this work?

Scrollview scrollY = (ScrollView)findViewById(R.id.scrollY);
LinearLayout scrollYChild = (LinearLayout)findViewById(R.id.scrollYChild);

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    scrollYChild.dispatchTouchEvent(event);
    scrollY.onTouchEvent(event);
    return true;
}

我还发现这一点: HTTP://blog.gorges .US / 2010/06 / Android的二维,滚动型/ 但我不明白的一切是如何实现这样的长片code正确的。

I have also found this: http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/ but I'm don't understand at all how to implement such a long piece of code properly.

这是没有多大意义,我认为二维滚动是一个web视图固有的,但在其他地方根本不存在......任何及所有的帮助是AP preciated。

It doesn't make much sense to me that two-dimensional scrolling is inherent in a webview but nonexistent elsewhere... Any and all help is appreciated.

编辑:为什么说当在画廊的图像放大了这项工作。当然必须有办法在这里实现了同样的功能。

How exactly does this work when zoomed in on an image in the gallery. Surely there has to be a way to implement that same functionality here.

推荐答案

林不知道你已经发布了博客,这是我的解决方案:

Im not sure about the blog you have posted, this was my solution:

/**
 * This class disables Y-motion on touch event.
 * It should only be used as parent class of HorizontalScrollView
 */
public class ParentScrollView extends ScrollView {
    private GestureDetector mGestureDetector;
    View.OnTouchListener mGestureListener;

    @SuppressWarnings("deprecation")
    public ParentScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mGestureDetector = new GestureDetector(new YScrollDetector());
        setFadingEdgeLength(0);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if( mGestureDetector.onTouchEvent(ev)&super.onInterceptTouchEvent(ev)){
            return true;
        }else{

            return false;
        }
    }

    // Return false if we're scrolling in the x direction  
    class YScrollDetector extends SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if(Math.abs(distanceY) > Math.abs(distanceX)) {
                return true;
            }
            return false;
        }
    }
}

XML:

    <com.example.Views.ParentScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <HorizontalScrollView
            android:id="@+id/tlDBtable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >


        </HorizontalScrollView>
    </com.example.Views.ParentScrollView>

基本上只有卷​​轴veritcal将被禁用,因为您将使用一个新的自定义类的父滚动视图。然后你把HScrollview滚动视图中。该Parentscroll认为会通过触摸,即使它不是垂直于horiszontalscroll视图,这使得它的2D滚动效果。

Basically the parent scrollview which only scrolls veritcal will be disabled because you will use a new custom class. Then you put a HScrollview within the scroll view. The Parentscroll view will pass the touch even if its not vertical to the horiszontalscroll view which makes it 2D scrolling effect.

这篇关于二维滚动......需要反馈的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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