首页 > 开发 > Android > 正文

求教高手,置于底部的按钮怎么没了?

2017-09-08 15:24:16  来源:网友分享
    我原本是想把四个按钮置于底部,按钮上方用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。

解决方案

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