I have a FrameLayout
that loads Fragments
by tapping on tabs in a TabWidget
. I can't figure out how to make the height of the FrameLayout
as tall as its content, so that the whole containing ScrollView
will scroll together as one instead of a separate scrolling view.
Here's a visual example of this Fragment
's structure:
As you can see, the Frame Layout Visible Height only reveals one row of the Fragment, when in fact, there are a few. I can scroll within the FrameLayout
to see the other rows as it is now, but that's not what I'm going for. The FrameLayout
is made up of a LinearLayout
containing a GridView
with their layout_height
s set to wrap_content
.
I tried hardcoding the height of the FrameLayout
to something like 500dp and it works great except for the fact that it's no longer dynamically sized. Would I need to resize the FrameLayout
programmatically each time a new image is loaded into the inner content? Is there a layout attribute I can set so it'll stretch its height to match its inner content?
Here's my layout xml file:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="200dp">
<!-- CONTAINS USER INFO AND STATS -->
</RelativeLayout>
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:weightSum="2">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</ScrollView>
Thank you!
Since I'm going to set a bounty on this, I thought I'd share what I've figured out so far.
In the thumbnails, onSuccess
when each image is loaded, I'm calling a function in the GridLayout
that holds the images that counts the images and sets the height of the GridLayout
. This works fine, although it seems like it'd be a bit inefficient.
What I'm doing is setting the GridLayout
height and then calling requestLayout
and invalidate
on it and it's parent(s). This works, but not as the images loading. It'll work if I go to a different tab and return to the thumbnails, oddly enough. Which makes me think I'm not updating at the right time or on the right object.
Anyway, that said. Does anyone know how to make the height of a GridLayout
expand to hold its contents (instead of scrolling) so I can scroll the entire page (including the top section)?
I should also add the GridView
layout:
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:fastScrollAlwaysVisible="false"
android:fastScrollEnabled="false"
android:numColumns="3"
android:choiceMode="none">
</GridView>