I’m trying to add a RelativeLayout, that contains 2 TextViews, above a ListView as a header, but am having trouble. The code I have so far shows the ListView, the footer, but no header:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Header -->
<RelativeLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:id="@+id/headerIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/headerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#919191"
/>
</RelativeLayout>
<!-- Header -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
>
<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="No items"
android:padding="5dp"
/>
</LinearLayout>
<!-- Footer -->
<RelativeLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:id="@+id/footerIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/footerText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="right"
/>
</RelativeLayout>
<!-- Footer -->
</RelativeLayout>
UPDATE:
I have it partially working. The following code does show the header TextViews, but when I scroll the ListView, the header layout flickers and disappears. Why is working with layouts in Android so frustrating?
This is the code that partically works:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:id="@+id/headerIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#919191"
/>
<TextView
android:id="@+id/headerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#919191"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<TextView android:id="@android:id/empty"
style="@style/BaseStyle"
android:text="No keywords entered"
android:padding="5dp"
/>
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:id="@+id/statusUpdated"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/Status"
android:layout_alignParentLeft="true"
android:background="#919191"
/>
<TextView
android:id="@+id/statusItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Status"
android:layout_alignParentRight="true"
android:background="#919191"
/>
</RelativeLayout>
</RelativeLayout>
1 Answer