Search code examples
javaandroidtextviewscrollviewoncreate

onCreate/textView sizing issue


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.


Solution

  • ViewTreeObserver

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