2011-08-03 292 views
1

enter image description hereAndroid:为什么我的按钮不能填充父项?

我找不出为什么我的图标是这样格式化的。他们被设置为填写父母,但不是。我正在尝试制作底部导航栏。我想要一个很好的渐变,最后两个按钮都有,但按钮中的图像看起来没有正确格式化。如果我在布局中取出背景,他们的格式会更好,但不是我想要的。我在此之后对酒吧进行了建模:enter image description here 我认为最好将所有Imagebtns设置为具有@null背景,然后将黑色渐变作为父级背景,将灰度渐变设置为Imagebtn中的背景,用户在该页面上。 我不确定尝试完成我的最终游戏的最佳方式。这里是我的xml:

<LinearLayout android:id="@+id/navbar" 
    android:layout_alignParentBottom="true" 
    android:layout_width="fill_parent" android:background="@drawable/navbackground" 
    android:layout_height="60dip" android:layout_weight="1" 
    android:orientation="horizontal"> 

    <ImageButton android:layout_height="fill_parent" android:id="@+id/navhomebtn" android:enabled="false" 
     android:textColor="#FFF" android:src="@drawable/homeiconsel" android:background="@null" 
     android:layout_weight=".25" android:layout_width="0dip" /> 

    <ImageButton android:layout_height="fill_parent" android:id="@+id/navsearchbtn" 
     android:textColor="#FFF" android:background="#FFF" 
     android:text="Search" android:layout_weight=".25" android:src="@drawable/searchicon" 
     android:layout_width="0dip" /> 

    <ImageButton android:layout_height="fill_parent" android:id="@+id/navfavbtn" 
     android:textColor="#FFF" android:background="@drawable/navbuttons" 
     android:src="@drawable/favoriteicon" android:layout_weight=".25" 
     android:layout_width="0dip" /> 
    <ImageButton android:layout_height="fill_parent" android:id="@+id/navloanbtn" 
     android:textColor="#FFF" android:background="@drawable/navbuttons" 
     android:src="@drawable/loanicon" android:layout_weight=".25" 
     android:layout_width="0dip" /> 

</LinearLayout> 

注:粉红色的背景是只是我与玩弄从谷歌开发资源here,我将其更改为较深的梯度,但我想强调的问题。

回答

1

我把你的xml替换成我自己的图片了。 一切似乎都很好。 也许无论你的布局嵌套在影响的东西。

截图和代码如下:

<LinearLayout android:id="@+id/navbar" 
     android:layout_alignParentBottom="true" android:layout_width="fill_parent" 
     android:background="@drawable/icon" android:layout_height="60dip" 
     android:layout_weight="1" android:orientation="horizontal"> 

     <ImageButton android:layout_height="fill_parent" 
      android:id="@+id/navhomebtn" android:enabled="false" 
      android:textColor="#FFF" android:src="@drawable/heart" 
      android:background="@null" android:layout_weight=".25" 
      android:layout_width="0dip" /> 

     <ImageButton android:layout_height="fill_parent" 
      android:id="@+id/navsearchbtn" android:textColor="#FFF" 
      android:background="#FFF" android:text="Search" 
      android:layout_weight=".25" android:src="@drawable/heart" 
      android:layout_width="0dip" /> 

     <ImageButton android:layout_height="fill_parent" 
      android:id="@+id/navfavbtn" android:textColor="#FFF" 
      android:background="@drawable/icon" android:src="@drawable/heart" 
      android:layout_weight=".25" android:layout_width="0dip" /> 
     <ImageButton android:layout_height="fill_parent" 
      android:id="@+id/navloanbtn" android:textColor="#FFF" 
      android:background="@drawable/icon" android:src="@drawable/heart" 
      android:layout_weight=".25" android:layout_width="0dip" /> 

    </LinearLayout> 

image buttons fill the space as expected

+0

我同意。无论布局如何嵌套,都可能导致问题。父容器是口述这个宽度的。 – slund