Android:带有相同空格按钮的底部导航栏

时间:2011-07-29 15:28:33

标签: android xml layout button menu

您好我正在尝试为我的应用程序创建一个类似于iphone zappos应用程序的底部导航栏:enter image description here

我目前在相对布局中有一个线性布局。代码在这里:

    <LinearLayout 
android:layout_alignParentBottom="true" 
android:layout_width="wrap_content" 
android:layout_height="60dip"
android:orientation="horizontal">

    <Button 
    android:layout_height="fill_parent" 
    android:id="@+id/navhomebtn" 
    android:text="Home"
    android:layout_width="wrap_content" />

    <Button 
    android:layout_height="fill_parent"
    android:id="@+id/navsearchbtn" 
    android:text="Search" 
    android:layout_width="wrap_content" />

    <Button 
    android:layout_height="fill_parent" 
    android:id="@+id/navfavbtn" 
    android:text="Favorites" 
    android:layout_width="wrap_content" />
    <Button 
    android:layout_height="fill_parent" 
    android:id="@+id/navloanbtn" 
    android:text="Loans" 
    android:layout_width="wrap_content" />

</LinearLayout>

当我更改按钮以填充父级时,它们只是相互重叠而不尊重其他大小。我希望让他们填补这个空间,所以不同尺寸的手机都会有类似的UI体验。否则,我必须将它们设置为固定宽度,并使其以混合的背景为中心(我不想这样做)。

请帮忙!

4 个答案:

答案 0 :(得分:1)

在LinearLayout中使用1的layout_weight,并在按钮中使用0dp作为layout_width,使用0.25作为layout_weight。

答案 1 :(得分:1)

在按钮上使用layout_weight。将所有按钮的layout_weight设置为1,每个按钮的父宽度为1 / n。

答案 2 :(得分:0)

尝试为每个layout_width传递0dip。

答案 3 :(得分:0)

正如其他人提到的,最简单的方法是将layout_width设置为0dip并设置layout_weight。另一种方法是使用RelativeLayout,并手动设置layout_alignParentLeft / Right和layout_toLeft / Rightof。