我有一个包含
ListView
和TextView
的GridLayout
。当向ListView
添加项目时,它会增长并将下方的TextView
推出屏幕。我认为在ListView
上设置layout_gravity="fill"
可以使其不增长,而是占用所有可用空间。
如何配置ListView
以使用可用空间而不是增长并将视图推到屏幕下方?
我正在寻找使用GridLayout
的解决方案。我知道在我的情况下,也可以使用LinearLayout
。但是这只是一个最小化的测试用例来说明我的问题。
如果可能,我不想以编程方式设置高度。
<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
的高度不是固定的,而是随着新内容的添加而扩展,所以除非您使用具有权重的LinearLayout
或RelativeLayout
作为ListView
和TextView
的包装器,否则无法通过 XML 属性实现所需的行为。 - Onik