Increasing the size of a TextView, according to the amount of data inserted in it

4

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

I'm displaying data within a TextView . But there comes a time when size is not enough. Look at the pictures.

App Home Photo:

PhotoActivityReport,whereIdisplaythedata:

So, look at where I had to pull ScrollView , to be able to view everything. I did not want this. I wanted the screen of the size adjusted with the cell phone, the small size, and as long as I was inserting the data into TextView , it would increase. If there is no way to do it, using TextView , could you help me?

    
asked by anonymous 22.09.2015 / 03:17

3 answers

4

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

Its value can be a fixed dimension, expressed as a decimal value, or a constant that defines how the size fits automatically. The constants are:

match_parent - view should be as big as your parent (minus padding )
fill_parent > - Same as above but considered obsolete since API Level 8
wrap_content - The view should be large enough just to include your content (plus the padding ).

In order for your TextView to automatically adjust your height based on the length of the text you should declare your layout_height as wrap_content p>

android:layout_height="wrap_content"
    
22.09.2015 / 11:27
2

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

  

Remembering that after a scrollView can only exist an 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> 
    
22.09.2015 / 15:42
0

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

    
22.09.2015 / 15:37