2012-02-28 107 views
1

我在XML中有以下佈局添加到滾動視圖TextView的

<Relativelayout..... 
     <TextView 1........../> 

     <ImageView........./> 

     <Textview 2......../> 
</Relativelayout> 

我需要添加垂直滾動型到TextView的2如何做到這一點我已經添加了FOLL代碼,但沒有工作...

<LinearLayout> 

    <ScrollView > 

     <TextView /> 

    </ScrollView> 
</LinearLayout> 

請幫助

+0

如果你只是想滾動一個TextView,你爲什麼不使用TexViewObject .setMovementMethod(new ScrollingMovementMethod())建議在這裏http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android – 2012-02-28 11:47:24

回答

2

在您的活動做這樣的事情:

TextView textDisplayed =(TextView) findViewById(R.id.textView1); 
textDisplayed.setMovementMethod(new ScrollingMovementMethod()); 

希望這有助於。

+0

只需在佈局xml文件中添加此佈局android:maxLines和android:scrollbars =「vertical」屬性的textview。然後使用.java – Goofy 2012-02-28 11:58:28

+0

中的TexView.setMovementMethod(new ScrollingMovementMethod())感謝它爲我工作,同時我也評論應該在.java中添加什麼,以便它完美地工作 – Goofy 2012-02-28 11:59:25

0

了滾動和你的TextView之間添加一個ViewGroup(如LinearLayout中)。 AFAIK,這是強制性的。

+0

什麼是AFAIK?在您的發言中 – Goofy 2012-02-28 11:47:13

+0

AFAIK是一個英文的「我知道的」首字母縮寫詞 – Sly 2012-02-28 13:10:35

0
<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 


     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="352dp" 
      android:layout_weight="1" 
      android:inputType="textMultiLine" > 

      <requestFocus /> 
     </EditText> 

    </LinearLayout> 
</ScrollView> 

這對我的作品

+0

但它顯示NULLpointer異常,因爲它無法找到LL – Goofy 2012-02-28 11:48:30

+0

中的texview id,對不起,順序應該不同,LinearLayout-> scrolliew - > TextView中。你確定在你的代碼中正確調用textview TextView tv =(TextView)findViewById(R.id.editText1); – Orlymee 2012-02-28 11:54:19

+0

是的謝謝你的幫助我得到了答案,請參閱接受的答案 – Goofy 2012-02-28 12:23:06

0

這絕對是罰款加scroview上的TextView但保留一件事在腦子裏只有TextView的高度應該更然後滾動視圖高度

<LinearLayout> 

    <ScrollView > 

     <TextView /> //textView 2 

    </ScrollView> 
</LinearLayout> 
相關問題