首页 > 解决方案 > 如何在布局中包含 listView 以及布局中的其他视图

问题描述

我有一个ImageView顶部和TextView底部的活动。我想ListView在两者之间添加一个,我该怎么做?

标签: javaandroid

解决方案


将线性布局作为父布局并使其方向垂直。依次添加imageview、listview、textview。现在为 listview 提供权重为 1,其高度为 0dp。为 listview 提供权重 1 将允许它在布局的整个空白空间中传播。希望这可以帮助

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="100dp" />

<ListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


推荐阅读