Increasing the size of a Textview, according to the amount of data entered in it

Asked

Viewed 1,050 times

4

I am developing an app, for technical course work, and I have the following situation:

I’m displaying data inside a Textview. Only there comes a time when the size is not enough. Observe the images.

Photo of the App Start:

inserir a descrição da imagem aqui

Photo of Activity Report, where I display the data:

inserir a descrição da imagem aqui

So look where I had to pull the Scrollview, so you can show it off. I didn’t want this. I wanted the screen size adjusted with the mobile phone, the small size, and according I was entering the data in Textview, it will increase. In case there’s no way to do it, using Textview, could help me ?

3 answers

4

The attributes that determine the size of a View sane android:layout_width and android:layout_height

Its value can be a fixed dimension, expressed by a decimal value, or a constant that defines how the size automatically adjusts.
Constants are:

match_parent - To view should be as big as your father (minus the padding)
fill_parent - The same as the previous but considered obsolete since the API Level 8
wrap_content - To view should be large enough only to include its content (plus padding).

So that your Textview automatically adjust its height depending on the length of the text you should declare your layout_height as wrap_content.

android:layout_height="wrap_content"

2

To solve your problem add one scrollView first of all, as the example shows:

Remembering that after a scrollView there can only be one element, so I put a LinearLayout, there inside this LinearLayout you put your elements.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"  
            android:orientation="vertical" >

            // aqui coloque o conteúdo do sua Activity

       </LinearLayout>
    </ScrollView>
</LinearLayout> 

0

You can in this case do with layout_weight if you want to occupy the whole screen, since you have several resolutions and sizes, in the layout_weight you can set by percentage, or else use linear_layout even without defining the height leaving with layout_height="wrap_content".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.