I have text view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/item_table_light_grey"
          android:gravity="center"
          android:orientation="vertical" >
    <TextView
            android:id="@android:id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            />
</LinearLayout>
When I change size of text using code
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTextSize(adapter.getTextSize());
width and height of textView not changed though text size changed successfully. What am I doing wrong?
Android does NOT refresh layout of views with "wrap_content" once it has been displayed.
So if you add a child view, or modify the content dynamically, you're screwed.
To solve that, I've written a static class that recomputes the sizes and forces the update of the layout for the views with "wrap_content". The code and instructions to use are available here:
https://github.com/ea167/android-layout-wrap-content-updater
Another solution is to set fixed values to layout_width and layout_height, add gravity="center" on the TextView, and remove the wrap_content
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With