2011-08-03 289 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