如何在scrollChange事件上获取android scrollview的第一个可见子项 [英] How to get First Visible child item of android scrollview on scrollChange event

查看:61
本文介绍了如何在scrollChange事件上获取android scrollview的第一个可见子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每个滚动更改事件上从 android 滚动视图中获取第一个可见子视图.比如,当我们向下滚动时,我们会得到所有即将出现在屏幕上的视图 ID 或引用.如何?

I want to get First visible child view from android scrollview, on each scroll change event. Like, when we scroll down, we get all the upcoming view id or reference that's just being visible on screen. How?

推荐答案

我自己搞定的.. 这是我的代码:

I got it on my own.. Here is my code:

在这里,我们需要创建自定义回调侦听器.在它的 onScrollChanged() 中,我们得到 int t 这是滚动的 Y 位置.另外,我们需要子行高度,然后将 t 除以 rowHeight.完毕.我们可以进一步使用 getChildAt().

Here, we need to create our custom callback listener. Inside its onScrollChanged(), We get int t which is scroll's Y position. Extra, we need child Row height and then just divide that t by rowHeight. Done. We can use getChildAt() further.

scrollView.setOnScrollViewListener(new OnScrollViewListener() {

    @Override
        public void onScrollChanged(ScrollViewEx v, int l, int t, int oldl,int oldt) {

            int rowHeight = rowView.getHeight();

            int firstPos = t / rowHeight;

            scrollMainChildLL = (LinearLayout) v.getChildAt(0);

            gotTxtLL = (LinearLayout) scrollMainChildLL.getChildAt(firstPos);
    }
 }

这篇关于如何在scrollChange事件上获取android scrollview的第一个可见子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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