Defining layout to have a Static header and then list view

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Defining layout to have a Static header and then list view

Postby naresh » Fri Mar 06, 2009 9:39 am

Hi All,
I want to have a list view which in each row, shows a left aligned image and Text description for that image.

Apart from this list, I want to have a header on top of this list which is an ImageView in first row (line), and a small a desription(textview) in the second row.

So basically my requirement is to show and image and text as part of the header and then to show a list of items.

For showing the lsit view, I could able to populate the list view with image and text, but not sure about how to build the header views.

Please see my layout xml below and help me in building the layout to achieve my requirement. I am newbie in android, please correct me if i am wrong.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/category_icon"
android:layout_width="50px"
android:layout_height="50px"
android:gravity="left"
/>

<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:height="25sp"

/>
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
naresh
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 27, 2009 6:10 am

Top

Postby MrSnowflake » Fri Mar 06, 2009 11:00 am

What is your problem exactly? First of all, you don't need a second LinearLayout for the listview, that one can go in the root linearLayout. Second, the listview should have the layout_height set as wrap_content, otherwise it would push the other view out of the screen. Maybe you could set layout_weight="1" so it takes up the rest of the free screen.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby naresh » Fri Mar 06, 2009 1:57 pm

Hi,

Thanks for the response. My requirement is on this layout, I want to display a list of items and as a header on the screen (on top of list)I should be having some image in one row and a text in second row (Static header).

Is there any way to decalre this header in layout xml?

I was trying to add ListView.addView(TextView) in java code, the moment I add this view, I am not able to see the list on screen.

Thanks again,
Naresh
naresh
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 27, 2009 6:10 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests