Search code examples
androidandroid-layouttabsfill-parent

fill_parent not stretching background image


I am going crazy here. I swear I've had this work a thousand times before and it's like nothing is behaving correctly now. I have to be doing something stupid. A few days ago I was having issues with the background on a list view item not filling the parent to stretch across the height of the list view item. I finally gave up and just hardcoded a height for both to fix that. Now I'm just trying to set a background of an entire activity and have it fill it's parent so that the image covers the entire screen. This activity is within a tab. Here is the code for the tab controller and the activity I'm having issues with.

Tab Layout:

<?xml version="1.0" encoding="utf-8"?>
<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

        <FrameLayout
            android:id="@android:id/tabcontent"            
            android:layout_width="fill_parent"            
            android:layout_height="fill_parent">

        </FrameLayout>
</LinearLayout>
</TabHost>

Troublesome Activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">

<RelativeLayout
    android:id="@+id/localHeader"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:background="@drawable/header2">

    <Button
        android:id="@+id/changeCityButton"
        android:layout_width="80dip"
        android:layout_height="30dip"
        android:layout_marginRight="10dip"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:onClick="buttonChangeOnClickListener"
        android:text="Change"
        android:textColor="#FFFFFF"
        android:background="@drawable/local_deal_redeem_button" />

    <TextView
        android:id="@+id/cityName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/changeCityButton"
        android:textSize="20dip"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:shadowColor="#FF000000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="1"/>

</RelativeLayout>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/localHeader"
    android:fastScrollEnabled="true"
    android:cacheColorHint="#00000000"
    android:divider="@null"
    android:dividerHeight="0px"/>

</RelativeLayout>

This issue appears to only be happening on the new Bionic. the "@drawable/background" will only stretch as high as the listview is long. And if there are no items in the listview it will not show anything. I've even tried ripping it out of the layout and making it just an imageview and that didn't work either. It's like there is a wrap_content tag somewhere that I'm missing. Normally I would just say this is something screwey with the Bionic but seeing as how I had those issues with the ListView background I'm thinking I've got something messed up somewhere. Please help!!

Also in my manifest:

<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:resizeable="true" android:anyDensity="true"></supports-screens>

But I've tried removing that and no matter what values I put in that line it doesn't do anything in my app.

EDIT: I've just realized that if I put the image into a "fill_parent" scrollview the background will stretch accordingly. However since the screen contains a ListView, I cannot go this route. Something is wacky here.

EDIT 2: I just ripped out the listview and it worked perfectly. It is somehow related to the listview.

EDIT 3: I just solved the issue by setting ListView height to "wrap_content". I have no idea why "fill_parent" was causing this behavior on this device, but it is fixed so all is well now. I can't self-answer for another 6 hours so if someone wants to put this as an answer I will select it as correct. Thanks everyone!


Solution

  • I resolved it by setting ListView height to wrap_content. I have no idea why fill_parent was causing this behavior on this phone, but it is now correctly functioning so all is well. Thanks everyone!