How to make the textlayout not go beyond the screen
I have a program where I need to add line breaks to the textlayout
, but when I add \n
to it a certain number of times, the text goes beyond the screen. So here's how to fix it?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:background="#000000"
tools:context=".MainActivity">
<EditText
android:id="@ id/editText"
android:layout_width="351dp"
android:layout_height="46dp"
android:layout_toLeftOf="@ id/button"
android:fontFamily="monospace"
android:hint="Command"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toStartOf="@ id/button"
app:layout_constraintTop_toTopOf="@ id/guideline"></EditText>
<TextView
android:id="@ id/textView"
android:layout_width="378dp"
android:layout_height="657dp"
android:layout_marginEnd="16dp"
android:fontFamily="monospace"
android:gravity="top|right"
android:text="Hello World!"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toTopOf="@ id/guideline"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@ id/button"
android:layout_width="100px"
android:layout_height="100px"
android:layout_marginEnd="16dp"
android:background="#000000"
android:text="↲"
android:fontFamily="monospace"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@ id/guideline" />
<android.support.constraint.Guideline
android:id="@ id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="658dp" />
</android.support.constraint.ConstraintLayout>
CodePudding user response:
It is recommended to use match_parent or wrap_content or you can use 0dp to scale view based to constraints. I would recommend use 0dp for width(scale to your requirement) and wrap_cotent for width