开发者

Android: Why doesn't my button fill the parent?

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:

Android: Why doesn't my button fill the parent?

I thought it would be best to set all the Imagebtns to have @null background then have the dark gradient as the background in the parent and the gray gradient set as background in the Imagebtn when the user is on that page. I'm not sure of the best way of trying to accomplish my end game. Here is my 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>

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>

Android: Why doesn't my button fill the parent?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜