Search code examples
androidlayoutword-wrap

Textview/EditView Mulitline only wrap on line breaks


I have tried alsorts, but cannot seem to get android to only wrap on line breaks..

that is, with the following content:

This is line number 1 /r/n
This is a much much longer line number 2.. please don't wrap me /r/n

I am happy scrolling to see the content to the right.

I have tried applying a scrollview wrapper, as well as scrollHorizontally="true" but no success.

Any line that is too long is wrapping when i dont want it to.

Note: the text is all in one StringBuilder. with /r/n The lines break properly, but also break to wrap if too long (which i dont want). Setting max lines is not going to work, as i want more than one line....

I am trying to display a file's contents As is.

My layout currently (tried other stuff)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:clipToPadding="false"
        android:fillViewport="true"
        android:scrollbarStyle="outsideOverlay">

        <TextView
            android:id="@+id/tv_file_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:lineSpacingExtra="5dp"
            android:padding="10dp"
            android:scrollHorizontally="true"
            android:scrollbars="horizontal"
            android:text="some very long test in a line which hopefully shouldnt wrap as tht would be a crime against humanity :( lets now see"
            android:textColor="@color/black"
            android:textSize="20sp"/>
    </ScrollView>

</LinearLayout>

Solution

  • Changing from ScrollView to HorizontalScrollView will do the trick here.