Android: Why doesn't my button fill the parent?
I can't figure out why my icons are formatting in this way. They are set to fill the parent but are not. I am trying 开发者_开发技巧to make a bottom navbar. I wanted a nice gradient which the last two buttons have but the images in the button never seem to format correctly. If I take out the background in the layout they format better but not quite what I want. I'm modeling the bar after this:
<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>
Note: The pinkish background was just something I was playing around with from Google Dev Resources here, I would change it to a darker gradient but I wanted to highlight the problem.
I took your xml and replaced my own images in. Everything seems to work ok. Maybe whatever your layout is nested in is affecting things.
Screenshot and code below:
<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>
精彩评论