2012-12-31 16 views
1

我的TextView有問題。如何查看TextView中的所有文本

當我的文本視圖中的文本太長時,我無法再查看它,因爲我無法在手機上滾動它。

我的代碼如下:

<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> 

我怎麼能解決這個問題?

感謝您

回答

1

添加滾動型到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

要添加內滾動視圖的ImageView,刪除從那裏它是ImageView的,並將其添加像這樣,

<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> 
+0

謝謝。:)但滾動條很醜! – newbie

+0

將此添加到您的scrollView android:scrollbars =「none」。它會隱藏滾動條。 –

+0

如何在滾動視圖中包含圖像?有一個錯誤,我只能添加一個孩子 – newbie

2

將所有的意見裏ScrollView

例如:

<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> 
1
<ScrollView ... > 
    <TextView fill_parent etc./> 





</ScrollView> 
1

試試這個:

該設置,您TextView

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

然後用這個從你Activity

yourTextView.setMovementMethod(new ScrollingMovementMethod()); 

感謝。

2

請使用下面的XML代碼而不是您的代碼,它會解決您的問題。

<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> 
相關問題