0

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!

Community
  • 1
  • 1
steve-gregory
  • 7,396
  • 8
  • 39
  • 47

1 Answers1

0

I am checking the scroll position via the onTouch event:

horizontalScrollView.setOnTouchListener(actualScrollViewTouch);
Pang
  • 9,564
  • 146
  • 81
  • 122
Rich Morey
  • 343
  • 2
  • 11