0

I have a problem with adding text to TextView which is placed in horizontal LinearLayout in Fragment. After adding some text the view always shows only 1 line. TextView height is not wrapping to its content.

My xml file:

  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:paddingBottom="2dp"
        android:paddingTop="5dp"
        android:weightSum="100"
        android:gravity="center_horizontal"
        android:paddingRight="10dp">
        <TextView
            android:layout_width="0dip"
            android:layout_weight="28"
            style="@style/Theme.Material"
            android:layout_height="wrap_content"
            android:id="@+id/txt"
            android:gravity="center_horizontal"
            android:textColor="@color/black_blue"
            android:paddingRight="1dp"
            android:paddingLeft="1dp" />
        <TextView
            android:text=""
            android:layout_width="0dip"
            android:layout_weight="24"
            style="@style/Theme.Material"
            android:layout_height="wrap_content"
            android:id="@+id/txt1Value"
            android:gravity="center_horizontal"
            android:textColor="@color/black_blue"
            android:paddingRight="1dp"
            android:paddingLeft="1dp" />
        <TextView
            android:text=""
            android:layout_width="0dip"
            android:layout_weight="24"
            style="@style/Theme.Material"
            android:layout_height="wrap_content"
            android:id="@+id/txt2Value"
            android:gravity="center_horizontal"
            android:textColor="@color/black_blue"
            android:paddingLeft="1dp"
            android:paddingRight="1dp" />
        <TextView
            android:text=""
            android:layout_width="0dip"
            android:layout_weight="24"
            style="@style/Theme.Material"
            android:layout_height="wrap_content"
            android:id="@+id/txt3Value"
            android:gravity="center_horizontal"
            android:textColor="@color/black_blue"
            android:paddingLeft="1dp"
            android:paddingRight="1dp" />
    </LinearLayout>

I would appreciate any ideas how to solve it. Thanks in advance.

K.Bieda
  • 1
  • 1

1 Answers1

0

Just use

  TextView tv = findViewById(R.id.txt);
  String YOUR_TEXT = "Your text \n text \n text" 
  tv.setText(YOUR_TEXT + "\n" + "text text text")

than inside of the TextView there are will be as many lines as you put "\n".

aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
  • Thats not about it. My text is adding properly. But the height of text view in fragment layout only shows the 1 line. – K.Bieda Nov 19 '16 at 22:14
  • Than probably there is something wrong with style="@style/Theme.Material" – aleksandrbel Nov 19 '16 at 22:31
  • I dont think so cause everywhere is working fine and when i put some text in xml to Textview it is showing on the fragment view (height is adjusting to multilines). I think the problem is with the thing that fragment view is refreshing height is adjusting before text is changing – K.Bieda Nov 19 '16 at 23:06