android - 求教高手,置于底部的按钮怎么没了?
大家讲道理
大家讲道理 2017-04-17 11:22:52
[Android讨论组]
    我原本是想把四个按钮置于底部,按钮上方用listview填满,布局代码如下:

    <ListView
        android:id="@+id/alertlistview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F2F2F2" >
    </ListView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/indexbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="2dp"
        android:layout_weight="1.0"
        android:background="@drawable/buttonbackgroundindex"
        android:text="主   页"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/runbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="2dp"
        android:layout_weight="1.0"
        android:background="@drawable/buttonbackgroundindex"
        android:text="运  行"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/alerthistorybutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="2dp"
        android:layout_weight="1.0"
        android:background="@drawable/buttonbackgroundindex"
        android:text="报  警"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/mebutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:background="@drawable/buttonbackgroundindex"
        android:text="设   置"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:textStyle="bold" />
</LinearLayout>

这时切换到graphical layout是可以看到这四个按钮的,但是一旦放到真机上就没了这四个按钮,这是为什么?我该怎么做才能达到我想要的效果,跪求大神讲解T T。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
高洛峰

这是因为ListView的layout_height是wrap_content的,这样随着ListView数据的增加肯定会塞满这个屏幕,从而导致Button被“挤”到屏幕下方去了。
解决方法:将最外层的容器设置为RelativeLayout,接着把包含四个Button的LinearLayout放到ListView前面去,同时设置LineatLayout的layout_alignParentBottom等于true,接着设置ListView的layout_above=@id/(LinearLayout's id)

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号