开发者

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 a开发者_如何学运维nd 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!


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜