-4

For example, a TextView, whose original "width" in xml is "wrap_content". Then in java code, I set it to a specific value such as 50px.

Now I want to change it back to "wrap_content", by means of changing the "LayoutParameter", but it didn't work.

So what can I do with it? Thank you!

RESOLVED

TTTqiu
  • 1
  • 1
  • 5
    Possible duplicate of [Android Set textview layout width dynamically](https://stackoverflow.com/questions/4909301/android-set-textview-layout-width-dynamically) – Dima Kozhevin Oct 11 '17 at 07:17

1 Answers1

0

You can use the WRAP_CONTENT constant defined in ViewGroup.LayoutParams. Try something like this:

TextView tv = // your view here
ViewGroup.LayoutParams params = tv.getLayoutParams();
params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
tv.setLayoutParams(params);
Ben P.
  • 52,661
  • 6
  • 95
  • 123
  • I know and I've tried this way. But it didn't work. Seems it won't work AFTER having change width to a specific value. – TTTqiu Oct 11 '17 at 07:34