Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1139794
  • 博文数量: 103
  • 博客积分: 1897
  • 博客等级: 上尉
  • 技术积分: 1717
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-19 21:02
文章分类

全部博文(103)

文章存档

2013年(19)

2012年(84)

分类: 嵌入式

2012-05-15 10:19:16

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

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. // 最外面是一个相对的布局
  3. <RelativeLayout xmlns: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=""
  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>


阅读(14956) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

桔色花朵2012-05-16 21:20:25

呵呵,很不错啊~博主写的很好!