0

我编写了这样的简单 xml 布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ARRAYADAPTER" />

<ListView
    android:id="@+listview/lw"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

<Button 
    android:id="@+button/b1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="NEXT"
    android:gravity="center"/>

</LinearLayout>

并在列表视图中设置一个数组适配器。当我启动这个应用程序时,没有出现按钮。我想要做的是将布局分为三个部分: - 顶部的文本视图 - 中间的适配器(带有滚动) - 底部的按钮(或多个)。我该怎么做?

4

2 回答 2

2

我认为您的 Button 占用了所有空间android:layout_height="match_parent",请尝试android:layout_height="wrap_content"

于 2013-03-05T19:56:05.770 回答
1

将您的 ListView 声明更改为:

<ListView
    android:id="@+listview/lw"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

并将您的 Button 高度设置为wrap_content.

这将告诉 ListView 占用 TextView 和 Button 未占用的剩余空间。

于 2013-03-05T19:56:38.673 回答