ListView, each ListRow not as high as content

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

ListView, each ListRow not as high as content

Postby Saebekassebil » Thu Dec 31, 2009 3:40 pm

So I'm developing an app where I'm using a ListView as the main View.
I got an XML-file as template for each listrow.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent">
  10.  
  11.     <TableLayout android:layout_width="fill_parent"
  12.  
  13.         android:layout_height="wrap_content"
  14.  
  15.         android:stretchColumns="1">
  16.  
  17.         <TableRow>
  18.  
  19.                 <ImageView android:src="@drawable/android:ic_media_play"/>
  20.  
  21.        
  22.  
  23.                 <TableLayout android:layout_width="fill_parent"
  24.  
  25.                         android:layout_height="fill_parent"
  26.  
  27.                         android:stretchColumns="1">
  28.  
  29.                         <TableRow android:layout_height="fill_parent">
  30.  
  31.                                 <TextView style="@style/ListViewTextHeading" android:id="@+id/loved_list_title" android:layout_width="wrap_content" android:layout_height="wrap_content" />
  32.  
  33.                         </TableRow>
  34.  
  35.                         <TableRow android:layout_height="fill_parent">
  36.  
  37.                                 <TextView style="@style/ListViewText" android:id="@+id/loved_list_artist" android:layout_width="wrap_content" android:layout_height="wrap_content" />
  38.  
  39.                                 </TableRow>
  40.  
  41.                         </TableLayout>
  42.  
  43.                 </TableRow>
  44.  
  45.     </TableLayout>
  46.  
  47. </LinearLayout>
  48.  
  49.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


The problem is that the TextView "loved_list_artist" is barely showed, and is cutted of, so one can only see the top of the letters.
If I was coding XHTML/CSS that would probably be a "float" problem, but i can't seem to find the problem here.
Please help me.. :)
User avatar
Saebekassebil
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 31, 2009 3:35 pm

Top

Postby achie1266 » Thu Dec 31, 2009 6:21 pm

it might be because you are using layout_height=fill_parent.
layout_height=wrap_content is what you need in all the views that you posted.

I wonder why a part of it is being cutoff. you shouldn't be able to see even that part.

:arrow: One more thing is that you have an image and two TextViews in the whole layout. So it is even better and less expensive if you consider the performance, if you just put them all in a relativeLayout. That way your app will not be building all those tableLayouts and then the table rows. And since it is a list item you will be having many more of these views displayed at the same time. So I would recommend you avoid using TableLayout for stuff like these. let me know if you need help with that.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Saebekassebil » Fri Jan 01, 2010 12:14 pm

Thanks so much! It worked, changing the layout_height! :)

So, as you proposed, I've tried to change my layout to a RelativeLayout. But I get a runtime error..? And I'm pretty much sure it's the XML I've messed up :P
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="fill_parent">
  8.  
  9.    
  10.  
  11.                 <ImageView android:id="@+id/loved_list_image"
  12.  
  13.                         android:src="@drawable/android:ic_media_play"
  14.  
  15.                         android:gravity="center_vertical"/>
  16.  
  17.                
  18.  
  19.                 <TextView style="@style/ListViewTextHeading"
  20.  
  21.                         android:id="@+id/loved_list_title"
  22.  
  23.                         android:layout_width="wrap_content"
  24.  
  25.                         android:layout_height="wrap_content"
  26.  
  27.                         android:layout_toRightOf="@id/loved_list_image" />
  28.  
  29.                        
  30.  
  31.                 <TextView style="@style/ListViewText"
  32.  
  33.                         android:id="@+id/loved_list_artist"
  34.  
  35.                         android:layout_width="wrap_content"
  36.  
  37.                         android:layout_height="wrap_content"
  38.  
  39.                         android:layout_below="@id/loved_list_title" /> 
  40.  
  41. </RelativeLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


And I'm using this for my mapping, and populating of the listview:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ListView list = (ListView) findViewById(R.id.loved_list_listview);
  3.  
  4.                
  5.  
  6. SimpleAdapter trackAdapter = new SimpleAdapter(AClass.this, this.trackList, R.layout.loved_list_item, new String[] {"trackName", "bandName"}, new int[] {R.id.loved_list_title, R.id.loved_list_artist});
  7.  
  8. list.setAdapter(trackAdapter);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
User avatar
Saebekassebil
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 31, 2009 3:35 pm

Postby achie1266 » Sat Jan 02, 2010 8:25 am

Hey Happy New Year, :D
sorry but I am having a small vacation.
What do u mean by a runtime error. I can only uderstand what it is if you post the error message and if possible try to post the logcat message.

Any way try to check out your imageView.
I don't think an image view supports android:gravity tag when it is within a relative Layout. [I am not sure though.]
and the other thing is is the image source android:ic_media_play? Is it provided by android sdk? [again I am not sure about this]
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.           <ImageView android:id="@+id/loved_list_image"
  2.  
  3.               android:src="@drawable/android:ic_media_play"
  4.  
  5.               android:gravity="center_vertical"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I am just doing a quick reply as I cannot be testing anything out till late Sunday or Monday. hope it helps you. :)
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Saebekassebil » Sat Jan 02, 2010 11:56 am

Thanks again for your time!
Well, after you mentioned the LogCat, I've been trying to learn its (messy) interface, and I finally found some error messages, saying something about the XML attributes I had to set. So after some debugging it's now working.

Again, thanks so much for taking the time, it takes to help me.. :)
User avatar
Saebekassebil
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 31, 2009 3:35 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests