2012-07-21 182 views

回答

4

這將工作,訣竅是讓你想滾動內滾動視圖。

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

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

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

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="@string/text" /> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 
+0

thanx這是最簡單的 – dashh 2012-07-21 13:35:03

4

文本切斷意味着你遇到了什麼問題。嘗試下面的代碼。它的工作原理.....

使用XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="HERE I TOOK NEARLY 3-4 PAGES OF DOCUMENT. IT WORKED" /> 

</ScrollView> 

如果要創建動態是指,按照這個代碼: main.java:

oncreate() 
{ 
    ScrollView sv=(ScrollView)findViewById(R.id.scrollView1); 
    TextView tv=new TextView(this); 
    tv.setText("just keep the text what you want here"); 
    sv.addView(tv); 

} 

改變你的XML作爲以下之一:

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
</ScrollView> 

試試這個代碼。它的作品....

+0

thanx的代碼,但我做了同樣的事情,但當文本增加屏幕大小滾動應該是他們向下滾動以查看其餘文本,爲什麼它不是happen'n,pl指導我我是新的發展 – dashh 2012-07-21 12:51:06

7

在你的XML,寫這篇文章的TextView:

<TextView 
     android:id="@+id/txtDetails" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxLines="7" 
     android:scrollbars="vertical" 
     android:text="TextView" 
/> 

而且在Activity,這樣寫:

TextView txtDetails = (TextView) findViewById(R.id.txtDetails); 
txtDetails.setText("Your Text"); 
txtDetails.setMovementMethod(new ScrollingMovementMethod()); 

這將滾動文本TextView。無需寫入ScrollView

+2

我想知道爲什麼大家都在scrollview中推薦textview時,textview可以管理自己的滾動:P – Shubhayu 2012-07-21 05:49:56

+0

@Shubhayu:非常感謝...... :) – 2012-07-21 05:51:55

+0

這是正確的方式來顯示大文本。 – Chandu 2017-05-02 18:02:33