Zach Sperske
Zach Sperske

Reputation: 658

Android: Remove max width attribute from Text View

So I've got a text view with a maxWidth attribute set on it.

<com.workday.workdroidapp.sharedwidgets.KingfisherTextView
    android:id="@+id/contact_item_title"
    android:layout_width="wrap_content"
    android:maxWidth="@dimen/contact_cell_title_max_width"
    android:layout_height="wrap_content"
    style="@style/Title.Dark"
    android:maxLines="1"
    android:ellipsize="end"
    tools:text="Title" />

Say that I want to remove that maxWidth programatically because the text view which would normally make me want to constrain it is empty. How can I do that? The only method I seem to have access to is setMaxWidth, with no special value to remove the flag.

Upvotes: 3

Views: 1762

Answers (1)

Matt Robertson
Matt Robertson

Reputation: 3165

Simply call myTextView.setMaxWidth(Integer.MAX_VALUE). That is actually what TextView does internally:

private int mMaxWidth = Integer.MAX_VALUE;

https://android.googlesource.com/platform/frameworks/base/+/jb-mr0-release/core/java/android/widget/TextView.java

Upvotes: 5

Related Questions