0

I am currently having problems with a scrollable view within a tab on an android layout. The view scrolls past underneath the tabs without a scrollable view implemented in the tab layout as shown below.

http://i46.tinypic.com/2ccmp0w.png

When I place a scrollable view within the tabbed layout it shows a small scrollable view that appears buggy and unusable. Shown below.

http://tinypic.com/r/29ej2ft/6

The code for the tab host is below

<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:padding="5dp" />
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />        
</RelativeLayout>
</TabHost>

and this is the code for the tab with the scroll view implemented

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/todayScroll" 
android:layout_height="wrap_content"
android:layout_width="fill_parent" >

<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"      
    android:orientation="vertical" >

            <ExpandableListView
                android:id="@+id/ExpList"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:groupIndicator="@null" />   

</LinearLayout>
</ScrollView>

Any ideas of how to get the content to scroll correctly and not get in the way of the tabs would be greatly appreciated :) Thanks.

I've tried a fair few times but it's starting to get very frustrating.

EDIT: Here is the TabHostActivity file.

public class TabbedMainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_main);

    TabHost tabHost = getTabHost();

    // Tab for todays meals
    TabSpec todaysSpec = tabHost.newTabSpec("Todays");
    //you could set icon here as well as title
    todaysSpec.setIndicator("Todays");
    Intent todaysIntent = new Intent(this, TodaysMealsActivity.class);
    todaysSpec.setContent(todaysIntent);

    // Tab for future meals
    TabSpec futureSpec = tabHost.newTabSpec("Future");
    futureSpec.setIndicator("Future");
    Intent futureIntent = new Intent(this, FutureMealsActivity.class);
    futureSpec.setContent(futureIntent);

    // Tab for comments
    TabSpec commentsSpec = tabHost.newTabSpec("Comments");
    commentsSpec.setIndicator("Feedback");
    Intent commentsIntent = new Intent(this, CommentsActivity.class);
    commentsSpec.setContent(commentsIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(todaysSpec); // Adding todays tab
    tabHost.addTab(futureSpec); // Adding future tab
    tabHost.addTab(commentsSpec); // Adding comments tab
}
}

Cheers, Rmplanner

rmplanner
  • 97
  • 1
  • 2
  • 8
  • Why do you keep a listview inside a linearlayout inside a scrollview. Why cant you use just listview or listactivity? – san Aug 01 '12 at 03:25

1 Answers1

0

Edit from comments: An alternate solution (the one used by the OP) was found here.

Use android:layout_height="fill_parent" on your ScrollView. (Or, since fill_parent is deprecated, use android:layout_height="match_parent".)

First, remove your ScrollView, and replace your RelativeLayout with this:

<RelativeLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_above="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141
  • Hi, thanks for the speedy reply but unfortunately that didn't fix this issue. The scroll view is still small and unusable with both fill and match parent. – rmplanner Aug 01 '12 at 02:02
  • Can you edit your OP to show how you are including the `ScrollView` in your tabs? It seems possible that whatever is containing the `ScrollView` is using `wrap_content`. – Cat Aug 01 '12 at 02:04
  • As I am quite new to android I am unsure of your question but what I can gather from your question is that you are asking for the tab host activity. If so - I'll edit it now; if not please clarify if you want any more information. – rmplanner Aug 01 '12 at 02:14
  • If you question was regarding the XML. I have provided all of the XML that I have used in the tabs. The tab doesn't have any other content other than the expandable list view as it is created programmatically. – rmplanner Aug 01 '12 at 02:26
  • Also switch your `ExpandableListView` to be `android:layout_height="wrap_content"`. This *should* do it... – Cat Aug 01 '12 at 02:33
  • Unfortunately that didn't work either. Just to make sure I've got it correctly down though. I have my `ScrollView` height set to `fill_parent`; my `LinearLayout` height set to `wrap_content` and my `ExpandableListView` height set to `wrap_content` with the widths for each view set as `match_parent`. This is being a pain. Thanks for trying though. – rmplanner Aug 01 '12 at 02:56
  • Yeah, that should be correct... I'm out of ideas, then. Sorry... :( – Cat Aug 01 '12 at 02:57
  • Though now that I think of it, why are you using `ExpandableListView` within a `ScrollView`? The list should scroll by itself... – Cat Aug 01 '12 at 02:58
  • That's what I thought. But as shown through the first picture I provided it doesn't work, the scrolling element falls behind the tabs :( [link](http://i46.tinypic.com/2ccmp0w.png) – rmplanner Aug 01 '12 at 03:03
  • Is that the end of the content? As in, is the "Order" button under "Vege Patty" the last item in the layout? – Cat Aug 01 '12 at 03:05
  • That is the last element yes. Perhaps [this](http://i47.tinypic.com/51a3rp.png) screenshot represents the issue better. Note that the scroll bar appears on the tabs. I would assume that the scrollbar wouldn't do this. – rmplanner Aug 01 '12 at 03:10
  • This doesn't happen normally when working with tabs. For example, if you have an android phone, the manage/running applications settings scrollbar doesn't appear on the tabs and the scrolling finishes when it hits the internal storage element on the bottom. – rmplanner Aug 01 '12 at 03:13
  • I've edited my answer with a new solution that should rectify this issue. Be sure you've removed the `ScrollView` when using this. – Cat Aug 01 '12 at 03:15
  • Unfortunately I require a relative layout to align the tabs on the bottom but I will try implementing as much as the settings as you have provided with the relative layout. – rmplanner Aug 01 '12 at 03:21
  • This solution should still leave the `TabWidget` at the bottom of the page. Try it! :) – Cat Aug 01 '12 at 03:25
  • Unfortunately your solution isn't working? I'm unsure why but [here](http://i45.tinypic.com/vfa6ac.png) is the view I am presented with as well as the code for both the XML documents [here](http://pastebin.com/WvfMNTSF) – rmplanner Aug 01 '12 at 04:09
  • Hi Eric, I've found a solution by stealing the answer from this question. [here](http://stackoverflow.com/questions/5402328/how-to-show-tabs-at-bottom-rather-then-at-top). Thank you so much for your time. Much appreciated. – rmplanner Aug 01 '12 at 04:20
  • Ah, I had just discovered a solution using `RelativeLayout`. Glad you have it working finally! – Cat Aug 01 '12 at 04:21