How to position Android ListView over a view - without taking up full space

So that users can post comments, I have 2 views, vertically folded. ListView to display the entered comments and the LinearLayout footer, allowing the user to add a comment (which is basically an EditText and a button).

The footer should be attached to the foot of the screen, and the ListView should sit above it. This is similar to what you see on facebook for Android when you add comments.

However, I don’t want the ListView to initially occupy a full space - I want it to occupy only the space needed to display its rows, but to be able to grow into the remaining space when the user adds comments - always staying above the layout of the footer.

I tried LinearLayout, as Android suggested here : how can you align the button below and view the list above?

However, this causes the ListView to occupy all the space above the footer - when there are only a few comments - so it is mostly empty and looks weird.

I tried the RelativeLayout parent where the footer is attached using android:layout_alignParentBottom="true" ..... Positioning the ListView above the footer using android:layout_above="@id/footerLayout" leads to the same behavior as above ( ListView takes up all the remaining space). removing this allows the ListView to "grow", but it overlaps the footer if it gets too large.

Greetings.

+4
source share
2 answers

I think 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> 
+5
source

I assume that one way to do this would be to use the android:fillViewport in XML. See this Romain Guy blog post: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

+2
source

Source: https://habr.com/ru/post/1439549/


All Articles