Search code examples
androidworkspacefill-parent

"Workspace" child views not filling height on Google "iosched" app


I'm playing around with the iosched app from Google I/O 2011. Looking at the ScheduleFragment, I'm testing a different view on the Workspace children for flinging the pages back and forth. However, I'm having trouble getting my child views to fill the parent. I added several background colors and some padding to show where everything is laying out. Here's my test...

I added a red background color to the "Workspace" item in fragment_schedule.xml like this...

android:background="#cc0000"

Then, instead of using blocks_content.xml for the child view, I created my own pending_content.xml that is simply a green-background LinearLayout (with fill_parent for height) and a blue-background TextView (also with fill_parent for height) with a simple text line.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#00cc00"
    android:padding="5dip"
    xmlns:android="http://schemas.android.com/apk/res/android">
        <TextView
        android:id="@+id/text_view"
        android:background="#0000cc"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="Pending Content"
        android:textColor="#ffffff"
        />
</LinearLayout>

I add my view just like the I/O app has "days"...

ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_schedule, null);
mWorkspace = (Workspace) root.findViewById(R.id.workspace);

ShootView view = new ShootView();
view.index = mViews.size();
view.rootView = (ViewGroup) inflater.inflate(R.layout.pending_content, null);
view.label = "Pending";
mWorkspace.addView(view.rootView);
mViews.add(view);

And here's what I see when I view it on the device:

http://www.milescrew.com/images/workspace.png

You'll see that the red Workspace fills the available parent space, but the green LinearLayout does not. What am I missing?


Solution

  • I figured out a solution. I started debugging the onLayout in Workspace.java. In the child.layout function call, I changed child.getMeasuredHeight() to this.getMeasuredHeight() to use the height of the workspace instead.

    Seems to work fine for the case of a page that is shorter than the workspace height as well as a child that is bigger (a long ListView) that is larger than the height of the workspace.