Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Floating view below ListView  RSS feed

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am trying to achive something like this (please don't laugh, I am no artist ):

So, there is a ListView holding items and below it is a TextView, but it could be anything. On the first figure, the list is scrolled totally up (the [] marks the scroll thumb), but the linear layout is visible. On the second figure, the list is scrolled a little down, but the view below it is still visible. I don't even know how to name this effect - is the below layout floating (it kind of floats above the list) or fixed (it's position is fixed)?

My approaches:
1. tried to use ListView.addFooter - it is always put below the last item on the list, so it's not what I want
2. tried having a (vertical by default) linear layout with a wrapping list view, like this:

This doesn't even show the text view when I scroll to the end of the list! Why is that?

3. I tried RelativeLayout like this:

but the result is exactly the same as #2 - no text view shown at all. What the heck?

I am out of ideas as I know too little about Android's UI. Maybe someone could give me some pointers how I could write the layout XML?

Regards,
Raf
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to wrap your ListView in a ScrollView. Check this example...
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know (more or less) how to use ScrollViews, but the example you point doesn't even have a ListView inside the ScrollView. Moreover, there is this Google I/O talk by the ListView devs and they say never to place a ListView inside a (vertical) ScrollView, as both are scrollable, and when you scroll, which one should? Here is the link: http://code.google.com/events/io/2010/sessions/world-of-listview-android.html.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assign an android:layout_weight="1" to the list view, that will make the ListView take up all the space that's left after the button is displayed...
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thank you, that did the trick. I don't know what the weight means for now and what the defaults are, and so what the 1 on the list changes, but I will get to that. For now, it works just fine.
Big thanks.
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raf Szczypiorski wrote: I don't know what the weight means for now and what the defaults are, and so what the 1 on the list changes, but I will get to that.

The layout_weight property determines the ratio by which a control/widget shares any free space that is available in its container. Default value for weight parameter is "0" which means, a control will not take up any remaining space in the parent.

When you specified "1" for the ListView, it took up all the remaining space in the parent.
 
Pay attention! Tiny ad!
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!