确定何时为水平滚动视图放置箭头的代码

发布于 2025-01-07 17:07:36 字数 1296 浏览 0 评论 0原文

我正在开发一个使用可扩展列表视图作为其父视图的应用程序,并且在每个子视图中都有一个根据数据库信息动态加载的水平滚动视图。

HSV 中的所有按钮都是使用与 列表视图中的延迟加载。我能够向我的 HSV 添加箭头,但现在我想更进一步,仅当有足够的项目填充空间时才显示箭头,这样如果仅显示一项,则不应显示箭头。

由于列表从头开始,我可以默认隐藏“后退”箭头,但我不确定在哪里测试是否显示“前进”箭头。

        public Object getGroup(int groupPosition) {
        Object o;
        o = groups.get(groupPosition).getName();

        if(relativeLayout != null && horizontalScrollView != null && forward != null) {
            if(horizontalScrollView.getWidth() < relativeLayout.getWidth()) {
                forward.setVisibility(View.VISIBLE);
            } else {
                forward.setVisibility(View.INVISIBLE);
            }
        }

        // }
        return o;
    }

最初,我在 getChildView 中使用了此测试,其中填充了 Horizo​​ntalScrollView,但它发生得太快,并且 HSV 和相对布局显示的宽度为零。

现在我正在 getGroup 中测试它,因为它在子视图开始加载后被多次调用,但我认为这只有效,因为我的可扩展列表中有很多组。如果我有一组,我仍然会遇到同样的问题。

是否有一个理想的地方来检查子布局是否大于水平滚动视图?

更新:我设置了一个计时器,每 1000 毫秒检查一次,看看前进是否应该变为可见,然后退出。它不太漂亮,但它的工作原理不会使应用程序崩溃,所以我很高兴。抱歉问了一个不好的问题!

I'm working on an app that uses an expandable listview as its parent, and in each child view there is a horizontal scroll view that is loaded dynamically based on DB information.

All of the buttons in the HSV are compound images added dynamically using an implementation very similar to lazy loading in listview. I was able to add arrows to my HSV, but now I would like to take it one step further and only display arrows when there are enough items to fill the space, such that if only one item is showing then no arrows should be displayed.

Since a list starts in the beginning, I can hide the 'back' arrow by default, but I am unsure where to test whether or not to show the 'forward' arrow.

        public Object getGroup(int groupPosition) {
        Object o;
        o = groups.get(groupPosition).getName();

        if(relativeLayout != null && horizontalScrollView != null && forward != null) {
            if(horizontalScrollView.getWidth() < relativeLayout.getWidth()) {
                forward.setVisibility(View.VISIBLE);
            } else {
                forward.setVisibility(View.INVISIBLE);
            }
        }

        // }
        return o;
    }

Originally I used this test in getChildView, where the HorizontalScrollView was populated, but it happened too soon and bot the HSV and relativelayout displayed a width of zero.

Right now I am testing it in getGroup, because it is called multiple times AFTER the childview has started to load, but I think this only works because I have a lot of groups in my expandable list. If I had one group I would still have the same problem.

Is there an ideal place to check whether or not the child layout is larger than the horizontalscrollview?

Update: I set a timer that checks every 1000 ms to see if forward should be turned visible and then exits. Its not pretty, but it works without crashing the app, so I'm happy. Sorry for the bad question!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子 2025-01-14 17:07:36

我正在通过 onTouch 事件检查滚动位置:

horizontalScrollView.setOnTouchListener(actualScrollViewTouch);

I am checking the scroll position via the onTouch event:

horizontalScrollView.setOnTouchListener(actualScrollViewTouch);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文