I have multiple FrameLayout
inside a ScrollView
. In one of the FrameLayout
I'm loading a PreferenceFragment
. Now I need to set the height of the FrameLayout
to the height of the PreferenceFragment
to avoid nested scrolling (the PrefrenceFragment
is scrollable too).
How can I get the height of the PreferenceFragment
?
I tried to override onCreateView()
in the PreferenceFragment
class, and call View.getHeight()
, but its just returning 0.
Setting the FrameLayout
to wrap_content
, isn't working as well, its just taking the space of a single preference then...
edit:
I tried now to get the height by using addOnGlobalLayoutListener()
but the returned value is just the displayed height, not the full height of the PreferenceFragment
. So I'm just getting the height of one preference for wrap_content
or e.g. 300 if I set the height of the FrameLayout
to 300 in the xml. I need the full height of all preferences (visibile and not).
@Override
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
{
final View v = super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
if (v != null) {
ViewTreeObserver vto = v.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.d("TEST", "Height = " + v.getHeight() + " Width = " + v.getWidth());
ViewTreeObserver obs = v.getViewTreeObserver();
obs.removeGlobalOnLayoutListener(this);
}
});
}
return v;
}