1

I have two HorizontalScrollViews. Each has a layout containing 8 textviews. The top scrollView is being used as a header while the bottom one will be displaying data. I am trying to get the two rows of textViews to line up correctly. My solution to this is to make the width of the textViews in the bottom scrollView match the width of the textViews in the top scrollView. I'm currently accessing the width property of the first textView in the first scrollView and trying to assign it to the second textView in the second scrollView tvBtm1.setWidth(tvTop1.getWidth()); I'm doing this in my onCreate method. The problem I'm running into is the UI isn't drawn until after onCreate so tvTop1.getWidth() is returning zero. I currently have my sizing function attached to a button, however I would like it to run on application start up. Is there any way to do this as it does not work in the onCreate method?

Side note: I already have the two scrollViews tied together so when I scroll one the other also scrolls. The exception to this is when I fling.

Bud
  • 13
  • 2
  • Sorry for the delay. I did some searching on the ViewTreeObserver and found this -> [http://stackoverflow.com/questions/4393612/when-can-i-first-measure-a-view]. About halfway down he mentions posting a runnable. I implemented this and it works like a charm! – Bud Jun 04 '15 at 02:22
  • nice oh yea and you can [check this too](http://stackoverflow.com/questions/30553745/addonlayoutchangelistener-vs-addongloballayoutlistener-vs-postrunnable-r/30554143#30554143) ; also accept if it helps – Elltz Jun 04 '15 at 03:01
  • I'd love to up vote your help but it's saying I don't have enough reputation to do so – Bud Jun 13 '15 at 18:30
  • well you do not have enough post on stackoverflow either, you need 15 reps Sir, you can contribute to the forum and when you get more reps you can come back and upvote, :), also you can accept the answer to get an extra 2 reps – Elltz Jun 14 '15 at 06:50

1 Answers1

0

ViewTreeObserver

check the link and also search about it on stackoverflow. there are tons of examples

Elltz
  • 10,730
  • 4
  • 31
  • 59