newbie
newbie

Reputation: 14950

how to view all text inside TextView

I am having a problem with my TextView.

When the text inside my text view is too long, i cannot view it anymore because i cannot scroll it on my phone.

My code is as follows:

 <RelativeLayout 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:background="@color/lightgray"
        tools:context=".BucketItemDescActivity" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/imageView1"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="19dp"
            android:text="The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)
The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)."
            android:textSize="12sp" />

        <LinearLayout
            android:id="@+id/frameLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="#336699" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_marginLeft="25dp"
                android:textSize="15sp" 
                android:textColor="#FFFFFF"
                android:text="The Godfather (1972)" />

        </LinearLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/frameLayout1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="18dp"
            android:src="@drawable/movie1" />

    </RelativeLayout>

How can i solve this?

THank you

Upvotes: 1

Views: 147

Answers (5)

Andro Selva
Andro Selva

Reputation: 54322

Add a ScrollView to yourTextView,

<ScrollView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/imageView1"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="19dp"
            android:scrollbars="none">
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)
The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)."
            android:textSize="12sp" />

</ScrollView>

EDIT

To add ImageView inside scrollView, remove the ImageView from where it is and add it like this,

<ScrollView  android:layout_width="wrap_content"
    android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
            android:layout_below="@+id/imageView1"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="19dp"
            android:scrollbars="none">

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

            <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="18dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)
The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)."
            android:textSize="12sp" />
      </LinearLayout>  
</ScrollView>

Upvotes: 1

Dipak Keshariya
Dipak Keshariya

Reputation: 22291

Please Use below XML code instead of your code for that, it will solve your problem.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/lightgray" >

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

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

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/imageView1"
                android:layout_marginLeft="25dp"
                android:layout_marginRight="25dp"
                android:layout_marginTop="19dp"
                android:text="The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)
The Godfather is a 1972 American epic crime film directed by Francis Ford Coppola and produced by Albert S. Ruddy from a screenplay by Mario Puzo and Coppola. Based on Puzo&apos;s 1969 novel of the same name, the film stars Marlon Brando and Al Pacino as the leaders of a powerful New York crime family. The story, spanning the years 1945 to 1955, centers on the ascension of Michael Corleone (Pacino) from reluctant family outsider to ruthless Mafia boss while also chronicling the Corleone family under the patriarch Vito Corleone (Brando)."
                android:textSize="12sp" />

            <LinearLayout
                android:id="@+id/frameLayout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:background="#336699" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_marginLeft="25dp"
                    android:text="The Godfather (1972)"
                    android:textColor="#FFFFFF"
                    android:textSize="15sp" />
            </LinearLayout>

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/frameLayout1"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="18dp"
                android:src="@drawable/movie1" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

Upvotes: 2

Pratik Sharma
Pratik Sharma

Reputation: 13415

Try this :

Set this to your TextView :

android:maxLines = "AN_INTEGER"    
android:scrollbars = "vertical"

And then use this from your Activity:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

Thanks.

Upvotes: 1

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

<ScrollView ... >
  <TextView fill_parent etc./>





</ScrollView>

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

Place all the views inside ScrollView.

For example:

<RelativeLayout
       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:background="@color/lightgray"
        tools:context=".BucketItemDescActivity">

  <ScrollView>
     <TextView/>
     <TextView/>
     ..........
     ..........
     ..........

  </ScrollView>
</RelativeLayout>

Upvotes: 2

Related Questions