1

I am following this example (First comment), How to create a custom ListView with "extends Activity"?

What i want is to make that exact same list but without that TextView at the top. Tried to delete it but had to reinstate it since the array adapter will not work without one (?)

So i got this code, see below, is working but i am a bit unhappy with my margin solution. I would like to do the same but with no margin. Margin far down at the bottom: android:layout_marginTop="20dip"

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffccd0"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#ffb0b6"
        android:textColor="#b3000d"
        android:textStyle="bold"
        android:typeface="sans"
        android:visibility="invisible" />

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"            
            android:background="#570000" >

            <TextView
                android:id="@+id/tv_1"
                android:layout_width="70dip"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|left"
                android:paddingLeft="20dip"
                android:text="Abbr"
                android:textColor="#FFFFFF"
                android:textSize="16dip"
                android:textStyle="bold"
                android:typeface="serif" >
            </TextView>

            <TextView
                android:id="@+id/tv_2"
                android:layout_width="200dip"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/tv_1"
                android:gravity="center_vertical|left"
                android:text="Countries"
                android:textColor="#FFFFFF"
                android:textSize="16dip"
                android:textStyle="bold"
                android:typeface="serif" >
            </TextView>
        </RelativeLayout>

        <ListView
            android:id="@+id/lv_country"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:cacheColorHint="#00000000" android:layout_marginTop="20dip">
        </ListView>


</RelativeLayout>
Community
  • 1
  • 1
Patrick
  • 5,442
  • 9
  • 53
  • 104

1 Answers1

3

Set an Id to the TextView and the RelativeLayout, then set to your ListView:

android:layout_below="@id/your_relative_layout_id"
android:layout_above="@id/your_text_view_id"

you can set, to your ListView, in addition:

android:layout_height="0dp"

as you have set its height with the two other lines. It's more light.

Jeje Doudou
  • 1,707
  • 1
  • 16
  • 24
  • This sort of works. I got rid of the margin. But how can i hide the textview altogether. Because right now its at the bottom and its cutting the list off at around 20dp from the bottom of the screen? Can i get rid of that somewhere altogether? – Patrick Jun 08 '12 at 11:38
  • Just remove the TextView and replace the "android:layout_above="@id/your_text_view_id"" in the List View by "android:layout_alignParentBottom="true"" – Jeje Doudou Jun 08 '12 at 11:41
  • If i remove the TextView, then nothing is displayed in the ListView. Found another solution. Setting the TextView height to 0dp, then it works. But it's still kind of stupid to have a TextView that is only there for the ListView (ArrayAdapter) to work. – Patrick Jun 08 '12 at 12:19
  • Don't you forget to replace the "android:layout_above="@id/your_text_view_id"" in the List View by "android:layout_alignParentBottom="true"", when you remove the TextView? – Jeje Doudou Jun 08 '12 at 12:50
  • I removed it but the list simply refuses to be populated? If i reinstate the TextView it works, if i remove it, i receive an empty ListView – Patrick Jun 08 '12 at 16:59