-1

I create my xml view, and in the preview it seems good. But when i play on my emulator the elements doesn't fix, i think the emulator is too small. So the solution i have tried is setting the scrollbars to vertical:

<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

But it doesn´t take effect, i think it is only for lists or long texts The preview of my aplication The real view

Gonz
  • 49
  • 4

5 Answers5

1

You need to use a ScrollView as the parent layout, something like the following:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center">

        <TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

    </LinearLayout>
</ScrollView>
Jagar
  • 777
  • 9
  • 24
0

Just wrap your current code into a Scrollview and it will scroll if the text is too large or overflow.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollview"
    >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</ScrollView>

Note that I am using match_parent which means it will take up all available space, so double check that you won't need something like wrap_content instead for the height / width.

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
0

I think the problem is that by default, a TextView is only a single line object. If you want to show multiple lines, you need to define them in your xml layout:

android:maxLines="10"
android:lines="5"
Michael Dougan
  • 1,698
  • 1
  • 9
  • 13
0

Try add android in your xml:

layout_marginBottom="16dp"

with this the TextView should be anleast 16dp from bottom or wrap it inside

Pavel Kostal
  • 221
  • 5
  • 13
0

You need to put your TextView inside a ScrollView for this. However, take note that a ScrollView can only have one direct child inside it (https://developer.android.com/reference/android/widget/ScrollView.html). If you need to put more than one view inside a scroll view you can put them inside a LinearLayout and then put this LinearLayout inside the ScrollView, like Jagar pointed out https://stackoverflow.com/a/57928644/12019759