Question

So I'm trying to create a screen which has a ListView and over that I need to be able to float another custom horizontal ListView, right at the bottom edge of the screen. When the user scrolls on the vertical listview, the horizontal one would go invisible and reappear when the scrolling stops. I figured FrameLayout would be my best bet for overlapping views. But I can't seem to make this work. The Horizontal listview seems to occupy the whole screen space. Any ideas? Is this even the right approach? I wish to have something similar to a fixed div in HTML.
Here's my XML:

UPDATE-1: Used RelativeLayout as suggested, but still a no-go. The HorizontalListView still seems to be occupying the whole screen. I'm using the HorizintalListView from here

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messages" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_marginTop="5dip" />


    <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <test.ui.app.HorizontalListView 
                android:id="@+id/folders"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="#FFFFFF" />

    </RelativeLayout>



</RelativeLayout>
Was it helpful?

Solution

I got it to work by setting the height of the inner Relative Layout myself instead of using 'wrap_content'.

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messages" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" />


    <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="80dip"
        android:layout_alignParentBottom="true" >

        <test.ui.app.HorizontalListView 
                android:id="@+id/folders"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="#FFFFFF" />

    </RelativeLayout>



</RelativeLayout>

OTHER TIPS

You cannot adjust the views inaide FrameLayout.So it will be better for you to go for RelativeLayout. Or you can put your listviews inside RelativeLayout or linearlayout and then you can adjust.

Hope this will help you. :)

Like the other answerer said, you could use a RelativeLayout:

  • set android:layout_alignParentLeft|Right|Top|Bottom="true" for the vertical list view
  • set android:layout_alignParentLeft|Right|Bottom="true" for the horizontal list view (and height to "wrap_content" or fixed size)

Or if you reeeeaaaally want to stick with FrameLayout (maybe for performance reasons...), you could somply add a huge android:layout_marginTop to the horizontal list view. But this solution is uglier, since you need to set exact values. For example if the whole screen is 320dp height, and you want the horizontal list view to be 80dp height, you need to set the top margin to 240dp. However if you run this on a screen with different aspect ratio, the horizontal list view will be ugly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top