In my android studio project I have a fragment (the class is MainFragment) and a scrollview inside. In MainFragment class I want to get event, when the fragment already layout it's child views. i.e I want to call a method scrollview.getHeight() and not to get 0, because of the system has not yet calculated actual height of scrollview. Is there any solution?
Asked
Active
Viewed 52 times
0
-
https://stackoverflow.com/a/24035591/2979171 – Alireza Sharifi Jul 02 '19 at 10:30
2 Answers
1
Do all the work on @Resume, in that time the fragment is created and the layout has been added so you should have the height
@Override
public void onResume() {
super.onResume();
// your code here ...
}

Granit Berisha
- 86
- 1
- 6
0
You can make use of the onViewCreated
method. It is called when the view is created so you won't be getting 0 height from there.
@Overrride
void onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
scrollView.doOnPreDraw {
println("Height: "+it.height)
println("Mesured Height: "+it.measuredHeight)
}
}

Birju Vachhani
- 6,072
- 4
- 21
- 43
-
-
@VahagChakhoyan i updated my answer. Please check now. Don't forget to upvote and mark as correct if it works! Let me know if it doesn't. – Birju Vachhani Jul 02 '19 at 11:46