views:

57

answers:

1

Hi,

I have a main menu screen with a simple ListView that contains "links" to further screens in my app (Browse, Bookmarks, Settings, About, etc.). Underneath the ListView there is a TextView (more accurately, a TextSwitcher that rotates TextViews) that changes every 10 seconds to display a new "tip". alt text

In portrait mode, this works fine. There are my five list items in the ListView , and my tip label underneath. However, when I switch to landscape mode, the ListView is taller than the screen. The ListView scrolls normally, but I cannot scroll past the end of the ListView to see the TextView underneath.

I have tried every possible combination of Layouts, wrappers, ScrollViews, and layout_height parameters and I simply cannot get it to behave.

Here is the simplest code I can use to get the result pictured above:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:orientation="vertical"
    android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/ListLayout"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ListView android:id="@id/android:list" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>
    </LinearLayout>
    <LinearLayout android:id="@+id/TipLayout"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_below="@+id/ListLayout">
        <TextSwitcher android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/TipSwitcher">
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:textSize="7pt"
                android:id="@+id/Tip1TextView" android:text="Tip: Hello, Android!"></TextView>
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tip: This is the second TextView in the TipSwitcher!"
                android:id="@+id/Tip2TextView" android:textSize="7pt"></TextView>
        </TextSwitcher>
    </LinearLayout>
</RelativeLayout>

Like I've said, I've already tried so many different combinations that I can't list them, and for the most part I was randomly inserting XML in an attempt to get something to work the way I wanted. So I'd greatly appreciate suggestions as to how I would go about doing this the right way.

Thanks.

EDIT: Something I forgot to mention, this may or may not be relevant. My MainMenuActivity is extending ListActivity. According to the docs, "ListActivity has a default layout that consists of a single, full-screen list in the center of the screen." But, "If you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate()." So I don't think the ListActivity is interfering.

+2  A: 

Put the TextSwitcher in the ListView itself. You can use addFooterView() for this.

CommonsWare
Huh, never thought of that. Didn't think it was possible to put Views inside anything other than a Layout. I am now able to see the TextSwitcher in landscape mode, however it is behind the ListView as opposed to underneath it.
Anidamo
@Anidamo: That should not be possible. If you have not done so already, you need to remove the `ViewSwitcher` from the layout XML file. Either construct it in Java code or inflate it from its own layout XML file, to get the View to provide to `addFooterView()`. Here is a sample project showing the use of `addFooterView()`: http://github.com/commonsguy/cw-advandroid/tree/master/ListView/HeaderFooter/
CommonsWare
Yep, that turned out to be the issue. Moved the TextSwitcher over to its own xml file, inflated it using View.inflate, and passed it to addFooterView. Had to call addFooterView *prior* to setAdapter (as per the javadoc) to get it working properly.Thanks.
Anidamo
One more small thing: since addFooterView is essentially adding another row to the listview, the Tip field is highlighted in orange when tapping on it. How can I stop that behavior?
Anidamo
@Anidamo: Using `addFooterView()`, you probably cannot stop that. At the cost of more complexity, you could steal a peek at my `MergeAdapter` and use its techniques to create your own adapter that stitches together your regular adapter and a third adapter that just returns your footer, with the appropriate methods set to "disable" that footer row. I have on my 18,000-item to-do list to add smarts to `MergeAdapter` directly to support this concept. http://github.com/commonsguy/cwac-merge
CommonsWare
@Anidamo: If, OTOH, you'd be more comfortable just saying the `TextSwitcher` was visible all of the time, anchor it to the bottom of the screeen (`android:layout_alignParentBottom="true"`) and anchor your `ListView` to the top of the screen (`android:layout_alignParentTop="true"`) and top of the `TextSwitcher` (`android:layout_above="@id/TipLayout"`).
CommonsWare
I'll take a look at the MergeAdapter to see if I can create something to do what I need. Thanks for the help.
Anidamo
Figured I'd mention that I was able to stop the orange highlight simply by setting the TextSwitcher's clickable property to true. Then, it intercepted tap events before they were caught by the ListView "underneath" it.
Anidamo