You should be able to set the width of the TextView for fill_parent, in which case it will do the wrapper for you. You should not set the width of your layouts as match_parent, as it is inefficient when you use layout layouts.
Since the Android layout system is sometimes mysterious regarding view sizes, if setting the TextView width to fill_parent actually makes it take up the whole screen (as your question seems to imply), follow these steps:
Set the width of the TextView to 0 by default. In onCreate your activity, after setting up the content:
findViewById(R.id.acciones).getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final int fragmentWidth = findViewById(R.id.releventFragmentId).getWidth(); if (fragmentWidth != 0){ findViewById(R.id.yourTextViewId).getLayoutParams().width = fragmentWidth; } } });
By initially setting the width of the TextView to 0, you do not allow it to change the width of the fragments. Then you can use the view tree observer to get the width of any fragment that interests you (by looking at its root view) after the layout has occurred. Finally, you can adjust the TextView to the exact width, which in turn will automatically wrap it.
Note that onGlobalLayout can be called several times and called regularly before all views are fully laid out, therefore, check! = 0. You also probably want to do some kind of check to make sure that you only set the width of the text view once, otherwise you may end up in an endless layout (but not at the end of the world, but not for performance).
source share