Will Tartak
Will Tartak

Reputation: 548

Android TextView not filling width, why?

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!

Upvotes: 2

Views: 4964

Answers (1)

inazaruk
inazaruk

Reputation: 74780

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.

Upvotes: 9

Related Questions