android – 二维滚动…一个需要反馈的建议

虽然花了大量时间谷歌搜索我的问题的相对简单的解决方案,我发现这是二维滚动的解决方案.我有一个嵌套在scrollview中的horizo​​ntalscrollview.我在几个方面摆弄了这个并且没有成功地制作任何功能.有没有人对如何制作这样的概念有任何想法?

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-dimensional-scrollview/但是我根本不明白如何正确地实现这么长的代码.

对我来说,二维滚动是webview中固有的但在其他地方不存在对我来说没有多大意义……任何和所有的帮助都是值得赞赏的.

编辑:放大图库中的图像时,这是如何工作的.当然,必须有一种方法来实现相同的功能.

解决方法:

我不确定你发布的博客,这是我的解决方案:

/**
 * 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.即使父级滚动视图不垂直于使其成为2D滚动效果的horiszontalscroll视图,它也会通过触摸.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...