I have a GridLayout
containing a ListView
and a TextView
. When items are added
to the ListView
it will grow in size and push the TextView
below it out of the
screen. I thought that by setting layout_gravity="fill"
on the ListView it
would not grow at all but rather take up all the available space.
How do I configure the ListView
to take up the available space instead of
growing and pushing views below it out of the screen?
I am looking for a solution using a GridLayout
. I am aware that in my case a
LinearLayout
would work aswell. However this is just a minimal test case to
illustrate my problem.
I do not want to set the height programmatically, if possible.
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="1"
app:useDefaultMargins="true" >
<ListView
app:layout_gravity="fill" />
<TextView
android:text="TextView" />
</android.support.v7.widget.GridLayout>
ListView's
height isn't fixed and expands with a new content you cannot achieve the desired behavior via xml attributes unless you use aLinearLayout
with weight orRelativeLayout
as a wrapper for theListView
andTextView
. – HardyGridLayout
although it contains onlyListView
andTextView
. If u don't want to scroll to showTextView
, just useRelativeLayout
. Use correct layout class. – Phraseology