I got a list from the web (link is here )
where it uses two xml layouts to create a list, the first xml is just the background where the second xml is going to be displayed as buttons in a list.
what I am trying to do is have that same list but add a tittle or a picture title at the top, i’ve been playing around with the list but i cant get it to work, the only way i can think to make this happen is somehow moving the position in which the second xml is displayed and have the top part to add whatever i like.
Thank you for the help and ideas to make this work!
[EDIT] code snippet…
First XML layout
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="schemas.android.com/apk/res/android";
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_weight="1"
android:scrollbars="none"
android:divider="#000000"
android:scrollingCache="true" android:layout_height="wrap_content"/>
Second XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#AA010101"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView android:id="@+id/list"
android:layout_width="1px"
android:layout_height="1px"
android:layout_weight="1">
</ListView>
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_height="fill_parent">
<ImageView android:id="@+id/img"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:scaleType="fitXY" />
<TextView android:layout_width="wrap_content"
android:id="@+id/title"
android:layout_height="wrap_content"
android:paddingTop="18dp"
android:layout_toRightOf="@+id/img"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_marginRight="50dp"
android:paddingLeft="10dp"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
You have to edit the XML file containing the
<ListView>, by adding whatever you want before (most probably aTextViewwith a Compound Drawable). So that what you called the “background” looks more like this:Main layout should host a
<TextView>(+eventuall a Compound Image) + a<ListView>.Secondary layout should host the content of each of your list item. If you have a
<ListView>in each XML layout, it means you will have a list of lists… I don’t know much about your list and app, and do not know what information you would like to display in each list item (e.g. ContactName, CalendarDate, Cities… whatever). But there are very few chances that you need a ListView in both of them.mainListLayout.xml
The Drawable can obviously be on the Right, Top or Bottom, and not only on the Left. You might also like to have a look at
android:drawablePadding="@dimen/xxxto add some extra space between text/title and the image. Drawable has to be one of your ic_* png files from res/drawable (eventually -hdpi, -mdpi and so on)itemLayout.xml