开发者

onTouch event problem

开发者 https://www.devze.com 2023-03-27 03:51 出处:网络
In my activity, I have a ScrollView with an OnTouchListener. This scrollView contains some imageViews.

In my activity, I have a ScrollView with an OnTouchListener. This scrollView contains some imageViews.

The problem is that when I touch an imageView, the onTouch(view,event) function of the OnTouchListener is called, but the view parameter is the scrollView instead of the imageView. Is it normal? How can I have the real touched view in parameter?

edit:

ScrollView scroll = (ScrollView)findViewById(R.id.affichagefiche_scrollview);
touchListener = new OnTouchScrollListener("---");
scroll.setOnTouchListener(touchListener);
private class OnTouchScrollListener implements OnTouchListener{开发者_高级运维
    public boolean onTouch(View view, MotionEvent event) {
        Log.d("activity", "onTouch: "+view.toString());
    }
}

The logs tells me that the view in parameters is always the scrollView, not a child


try bind OnTouchListener to imageViews or do it by getX,getY coords


it will be more easier if you use setOnItemClickListener to get individual imageView of ScrollView.Then use onItemClick(AdapterView parent, View view, int position, long id).

0

精彩评论

暂无评论...
验证码 换一张
取 消