如何检测里面的时候Horizo​​ntalScrollView景色倒是另一种观点? [英] How to detect when a view inside HorizontalScrollView touches another view?

查看:133
本文介绍了如何检测里面的时候Horizo​​ntalScrollView景色倒是另一种观点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想创造的iMovie像滚动视图,我想,当滚动视图中的图像按白线(这样我就可以改变大图)的回调。我该怎么办呢?

So I'm trying to create iMovie like scroll view, I want to get a callback when the image inside the scroll view touch the white line (so I could change the large image). How can I do that?

推荐答案

该解决方案适用于我,也这是我能够经过长期的研究方案,我们有Horizo​​ntalScrollView做出来,唯一的解决办法

This solution works for me and also this is the only solution I was able to make out after a long research on options we have with HorizontalScrollView.

ImageView的lineImage =(ImageView的)findViewById(R.id.yourImageViewIdOfWhiteLineImage);

ImageView lineImage=(ImageView)findViewById(R.id.yourImageViewIdOfWhiteLineImage);

然后在你的horizo​​ntalScrollView的onTouchListener

Then in onTouchListener of your horizontalScrollView

public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()){
    case MotionEvent.ACTION_MOVE:
     //get horizontal scroll view for images
    HorizontalScrollView parent=(HorizontalScrollView)v;
    //get linear layout for list of images
    LinearLayout wholeList=(LinearLayout)parent.getChildAt(0);
    int centerCord[] = new int[2];
    for(int idx=0;idx<wholeList.getChildCount();idx++){
        ImageView discoveredIv=(ImageView)wholeList.getChildAt(idx);
        discoveredTv.getLocationInWindow(centerCord);
        int discoveredX=centerCord[0];
        //set these (lineImage.getLeft()-20, lineImage.getLeft()+20) according to your 
        //requirement, the way it best suits you. You'll have to test in runtime, how your 
        //views come under the line and then set these.
        if(discoveredX >= lineImage.getLeft()-20 && discoveredX <= lineImage.getLeft()+20)
        {
            //you have a winner, take that image from imageView and set it wherever you want.
            //Your image is in discoveredIv
        }
    }
        return false;
    case MotionEvent.ACTION_UP:
        //It returns true to avoid fling effect, otherwise this method won't work.
        return true;
    }
return false;
}

这是严格按照您的要求。不过,我建议你在ACTION_UP情况下使用该code,因为如果你做所有这些计算在ACTION_MOVE那么这个code的倾向,使您的应用程序缓慢滚动时也,越多的计算应用程序变慢向下。 所以,我建议使用这ACTION_UP。

This is strictly according to your requirement. But I'd suggest you use this code in ACTION_UP case, because if you do all these calculations in ACTION_MOVE then this code has tendency to make your app slow while scrolling and also, more the calculations more the app slows down. so, i suggest to use this in ACTION_UP.

您可以测试您的应用程序在这两种情况下,决定在你想要这个code的情况下。

You can test your app in both cases and decide in which case you want this code.

这篇关于如何检测里面的时候Horizo​​ntalScrollView景色倒是另一种观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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