Android 底部菜单的实现方法

来源:互联网 发布:明星开的淘宝店 编辑:程序博客网 时间:2024/05/01 12:03
最近在写一个小功能模块的时候,出现一个小问题,就是要如何实现在一个android 界面中实现底部菜单,原先我是设置了layout 的gravity 属性,后来发现当界面顶部的内容增多时,就会把下面菜单的内容给覆盖了。。
  试验了好久。。我都快泪奔了。。后来,经过无数次的百度和google之后,我终于找到了解决的办法,那就是设置一个relativeLayout的布局,里面再设置两个直线的布局,其中那个要在底部的布局就设置一个属性。 android:layout_alignParentBottom="true",然后这个布局及其里面的控件就会默认呆在底部了。。
好,讲完思路,我贴一下我的布局文件。。

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. // 最外面是一个相对的布局
  3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     android:background="@drawable/ic_all_bg"
  7.     android:orientation="vertical" 
  8.     >
  9.     
  10. <LinearLayout //这是顶部的一个线性布局
  11.       android:layout_width="fill_parent"
  12.     android:layout_height="wrap_content"
  13.     android:id="@+id/top"
  14.     >
  15.  <include layout="@layout/list"></include>
  16. </LinearLayout>
  17.   <LinearLayout //这个是要常呆在底部的布局
  18.       xmlns:android="http://schemas.android.com/apk/res/android"
  19.       android:layout_width="fill_parent"
  20.       android:layout_height="wrap_content"
  21.      android:id="@+id/bottom"
  22.     android:layout_alignParentBottom="true" //设置了这个属性之后,就会默认呆在屏幕的底部
  23.       >
  24.        <Button
  25.        android:id="@+id/addDiaryBtn"
  26.        android:layout_width="fill_parent"
  27.        android:layout_height="wrap_content"
  28.        android:text="@string/addDiary" 
  29.        ></Button>
  30.    </LinearLayout>
  31.  
  32. </RelativeLayout>

0 0
原创粉丝点击