2012-02-28 82 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> 
相关问题