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,188
  • 8
  • 48
  • 84

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
  • 788
  • 5
  • 11