Reputation: 1813
I'm trying to place a banner at the top of a listview, one that stays there when the list scrolls down. The layout I currently have actually show what I want in the preview but when I run it in the emulator the only thing that appears is the list.
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/EdUniCrest" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_height="wrap_content" android:id="@+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_toRightOf="@+id/EdUniCrest"
android:layout_alignParentRight="true" android:layout_alignBottom="@+id/EdUniCrest"
android:background="#25476C"></TextView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@color/listcolor" android:orientation="vertical" android:layout_marginTop="50dp">
<ListView android:id="@android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/no_lunchs" />
</LinearLayout>
Anyway, I can't see why it isn't working. Does anyone have any idea what it might be?
Thanks.
Upvotes: 0
Views: 149
Reputation: 3542
The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.
Something like below should work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal" android:id="@+id/bannerBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:src="@drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/EdUniCrest"/>
<TextView android:layout_height="wrap_content" android:id="@+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:background="#25476C"/>
</LinearLayout>
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@android:id/empty" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="@string/no_lunchs" />
</LinearLayout>
Upvotes: 1
Reputation: 427
What if you wrapped your RelativeLayout
in a ScrollView
, and since a ScrollView
can only have one child, put the banner above it?
Upvotes: 0