Search code examples
androidandroid-layoutscrollview

How can i add a description in a ScrollView on separate lines?


How can i create a description within a scrollview? i would like to place a date on none line and a title on a separate line, but even with spaces and pressing enter it creates all on one line.

The code works well i just need help on being able to control what i write on what line. For example

date location title expiry

instead of writing them on separate lines it all goes onto the same line. Even using enter, tab, spaces.

MAIN ACTIVITY

 TextView mTitleWindow = (TextView) findViewById(R.id.titleWindow);
 TextView mMessageWindow = (TextView) findViewById(R.id.messageWindow);

    mTitleWindow.setText("BATMAN IS PART OF THE DC TRINITY");
    StringBuilder stringBuilder = new StringBuilder();
    String someMessage = "hello     hi" ;
    stringBuilder.append(someMessage);

    mMessageWindow.setText(stringBuilder.toString());

layout

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <TextView
            android:id="@+id/titleWindow"
            android:layout_width="352dp"
            android:layout_height="58dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="16dp" />


        <TextView
            android:id="@+id/messageWindow"
            android:layout_width="350dp"
            android:layout_height="455dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_marginEnd="17dp"
            android:layout_below="@id/titleWindow" />

    </RelativeLayout>
</ScrollView>

Solution

  • Hello @D_TECK use "\n" in string variable value for the separate line in message.

    String someMessage = "hello     \n hi";