添加一个按钮,在Android上一个列表视图下 [英] Adding a button underneath a listview on android

查看:129
本文介绍了添加一个按钮,在Android上一个列表视图下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在尝试添加一个按钮,机器人列表视图下,该问题是按钮不会出现。

 < XML版本=1.0编码=UTF-8&GT?;
< AbsoluteLayout
    机器人:ID =@ + ID / widget0
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <的ListView
        机器人:ID =@ + ID / MessageList中的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_x =0px
        机器人:layout_y =0px​​>
    < / ListView控件>
    <按钮
        机器人:ID =@ + ID / Add按钮
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=按钮
        机器人:layout_x =0px
        机器人:layout_y =379px>
    < /按钮>
< / AbsoluteLayout>
 

解决方案

AbsoluteLayout是pcated德$ P $。我建议,而不是你使用的LinearLayout:

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    机器人:ID =@ + ID / widget0
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <的ListView
        机器人:ID =@ + ID / MessageList中的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =0dp
        机器人:layout_weight =1>
    < / ListView控件>
    <按钮
        机器人:ID =@ + ID / Add按钮
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=按钮>
    < /按钮>
< / LinearLayout中>
 

我也建议通过开发文档阅读布局一个很好的介绍。

So Ive been trying to add a button underneath a listview in android, the problem is that the button does not appear.

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
    android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messagelist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="0px"
        android:layout_y="0px">
    </ListView>
    <Button
        android:id="@+id/addbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_x="0px"
        android:layout_y="379px">
    </Button>
</AbsoluteLayout>

解决方案

AbsoluteLayout is deprecated. I would suggest instead that you use a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messagelist"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1">
    </ListView>
    <Button
        android:id="@+id/addbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button">
    </Button>
</LinearLayout>

I'd also suggest reading through the developer docs on layouts for a good introduction.

这篇关于添加一个按钮,在Android上一个列表视图下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆