首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >在ListView末尾添加按钮

在ListView末尾添加按钮
EN

Stack Overflow用户
提问于 2015-09-16 19:33:40
回答 4查看 2.2K关注 0票数 1

我想在列表视图的末尾添加一个按钮。我有以下xml文件。“列表”视图显示其内容,但该按钮未显示。

代码语言:javascript
代码运行次数:0
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/myListView" />
    <Button
        android:text="Project Download"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/download" />
</LinearLayout>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-09-16 19:40:49

问题在于android:layout_height="match_parent"属性在您的ListView中。match_parent意味着列表视图将填充所有的空格。正确的方法是:

代码语言:javascript
代码运行次数:0
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:weight="1"
        android:id="@+id/myListView" />
    <Button
        android:text="Project Download"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/download" />
</LinearLayout>
票数 3
EN

Stack Overflow用户

发布于 2015-09-16 21:00:56

您的按钮没有显示,因为您的ListView占用了整个空间,在将其layout_height设置为match_parent时隐藏了您的按钮。match_parent将占用整个可用空间。因此,将其改为wrap_content,如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_parent"
        android:id="@+id/myListView" />
    <Button
        android:text="Project Download"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/download" />
</LinearLayout>

wrap_content将您的视图包装到最小可用的高度/宽度,而不会隐藏任何东西或使任何事情不清楚。

票数 1
EN

Stack Overflow用户

发布于 2017-08-07 14:21:48

我也有同样的问题,并且解决了。您只需要将该布局包装到ScrollView中即可。

代码语言:javascript
代码运行次数:0
运行
复制
<ScrollView 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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_transaction_history"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1">

            </android.support.v7.widget.RecyclerView>

            <Button
                android:id="@+id/btn_history_load_more"
                style="?borderlessButtonStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-medium"
                android:paddingBottom="@dimen/margin_big"
                android:paddingTop="@dimen/margin_large"
                android:text="@string/text_btn_load_more"
                android:textColor="#009CDE"
                android:textSize="@dimen/text_size_medium" />
    </LinearLayout>
</ScrollView>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32617180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档