Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 603
Will Tartak Avatar asked Mar 30 '26 02:03

Will Tartak


1 Answers

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.

like image 89
inazaruk Avatar answered Apr 02 '26 22:04

inazaruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!