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

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

问题描述

虽然我花了大量时间在谷歌上搜索一个相对简单的解决方案来解决我的问题,但我发现这是一个二维滚动的解决方案.我有一个嵌套在滚动视图中的水平滚动视图.我以几种方式摆弄了这个,但没有成功地使任何功能发挥作用.有没有人对如何制作这样的概念有任何想法?

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-two-Dimension-scrollview/ 但我完全不明白如何正确实现这么长的一段代码.

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.

二维滚动是 webview 固有的,但在其他地方不存在,这对我来说没有多大意义......感谢任何和所有帮助.

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>

基本上只滚动垂直的父滚动视图将被禁用,因为您将使用一个新的自定义类.然后在滚动视图中放置一个 HScrollview.即使Parentscroll 视图不垂直于使其成为2D 滚动效果的horiszontalscroll 视图,它也会传递触摸.

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天全站免登陆