2

I have the following layout and call to that layout. At one point this very same code would fill the width of the parent layout, a tab. Now it does not and I can't figure out why. It is keeping me from releasing my latest version. Any and all input is welcomed.

section_title.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/seasonTitle"
    android:padding="3dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="#FFFFFFFF"
    android:textSize="14sp"
    android:textStyle="bold"
    android:maxHeight="26sp"
    android:background="#FFCC3333"
     />

Here is a snippet of how it is called:

TextView titleTv = (TextView)mInflater.inflate(R.layout.section_title, null);
titleTv.setText(titleText);
mMergeAdapter.addView(titleTv);

Thanks!

Will Tartak
  • 548
  • 7
  • 17
  • 1
    Have you checked the parent layout parameters? E.g. orientation could be set to "horizontal" if it is a LinearLayout. – 87element Sep 05 '11 at 20:34
  • 1
    There could be another View that takes full width. – Salw Sep 05 '11 at 20:54
  • It turns out you are both right, it was a parent that was not taking the full width any more because of another view I had removed from it. The removed view was forcing it to be full width and now that it is gone the parent was not full width. – Will Tartak Sep 05 '11 at 21:01

1 Answers1

9

When you inflate your view without parent like this:

 TextView titleTv = (TextView)mInflater.inflate(R.layout.section_title, null);

Some android:layout_* parameters are just discarded. In order to avoid this, inflate your view with parent specified, but without attaching view to parent. Like this:

 TextView titleTv = (TextView)mInflater.inflate(R.layout.section_title, parent, false);

This should resolve your issue.

inazaruk
  • 74,247
  • 24
  • 188
  • 156