2

In my fragment, I have a couple of TextViews inside a LinearLayout. I set the text dynamically in onViewCreated(). The height is set in the XML-Layout by android:layout_height="wrap_content". However, the heights do not adjust to the content. They always stay same height.

Here is the XML:

<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/my_white_color">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/my_white_color"
    android:padding="10dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seminarImageView"
        android:scaleType="fitCenter"
        android:background="@color/gray3"
        android:padding="1dp"
        android:adjustViewBounds="true"
        android:layout_gravity="center_horizontal" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/titelTextView"
        android:textColor="@color/blue_heading"
        android:textSize="24sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/teaserTextView"
        android:textColor="@color/blue1"
        android:textSize="18sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bodyTextView"
        android:textColor="@color/blue1"
        android:textSize="15sp" />

</LinearLayout>

Any suggestions?

mrd
  • 4,561
  • 10
  • 54
  • 92
  • This seems to be exactly what you are looking for -> [Link to an older post](http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds/17782522#17782522) – Viral Patel Dec 19 '15 at 16:48
  • that's not what I am looking for: I don't want the content (text) to resize, I want the TextView to resize, that's a difference. – mrd Dec 19 '15 at 17:08
  • add android:linespacingextra="5dp" to your textview – HourGlass Dec 19 '15 at 17:22

1 Answers1

0

Try to call requestLayout() after setting the text.

I'm not sure, but onViewCreated() can be called after view is laid out.

Milos Fec
  • 828
  • 6
  • 11