Reputation: 1861
To allow users to submit comments, I have 2 views, vertically stacked. A ListView for displaying entered comments and a LinearLayout footer, for allowing the user to add a comment (which is basically an EditText and a button).
The footer must be anchored to the foot of the screen and the ListView must sit above it. Its similar to what you see on facebook for Android when you are adding comments.
However I don't want the ListView to initially take up the full space - I want it to take up only the space required to display its rows, but to be able to grow into the remaining space as the user adds comments - while always staying above the footer layout.
I've tried a LinearLayout as suggested here Android: How can you align a button at the bottom and listview above?
However, this results in the ListView taking up all the space above the footer - when there is only a couple of comments - so its mainly empty and looks weird.
I have tried a RelativeLayout parent, where the footer is anchored using android:layout_alignParentBottom="true"
..... Positioning the ListView above the footer using android:layout_above="@id/footerLayout"
forces the same behaviour as above (ListView takes up all remaining space)... removing this allows the ListView to 'grow' but it overlaps the footer if its grows too big.
Cheers.
Upvotes: 4
Views: 1385
Reputation: 45942
I guess this workaround will work!
<LinearLayout
layout_width="MATCH_PARENT"
layout_height="MATCH_PARENT"
orientation="vertical">
<LinearLayout
layout_width="MATCH_PARENT"
layout_height="0"
android:weight="1"
orientation="vertical">
<YOURLIST
layout_width="MATCH_PARENT"
layout_height="wrap_content"
/>
</LinearLayout>
<YOURVIEW
android:layout_width="MATCH_PARENT"
android:layout_height="WRAP_CONTENT"
android:weight="0"/>
</LinearLayout>
Upvotes: 5
Reputation: 690
I guess one way to do it would be using the android:fillViewport
attribute in the XML. See this blog post by Romain Guy: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
Upvotes: 2