Android不会滚动浏览文本文件

时间:2012-10-12 11:18:13

标签: android scroll android-xml

我在eclipse中有一个存储在res / raw中的helpdoc.txt文件。它使用以下代码显示在我的应用程序中:

public class HelpPage extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.help);
    //read in
    InputStream iFile = getResources().openRawResource(R.raw.helpdoc);
        try {
            TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
            String strFile = inputStreamToString(iFile);
            helpText.setText(strFile);
        } catch (Exception e) {
            //nothing here
        }
}//end onCreate

    /**
         * Converts an input stream to a string
            */
        public String inputStreamToString(InputStream is) throws IOException {
            StringBuffer sBuffer = new StringBuffer();
            DataInputStream dataIO = new DataInputStream(is);
            String strLine = null;
            while ((strLine = dataIO.readLine()) != null) {
                sBuffer.append(strLine + "\n");
            }//end while
                dataIO.close();
                is.close();
                return sBuffer.toString();
        }//end method  

它正确加载,但并非全部适合屏幕,当我尝试滚动时,我无法读取其余文本。

这是完整性的相关XML布局文件:http://pastebin.com/PtskJbqt

有人可以建议我如何向下滚动以确保用户可以阅读整个文件吗?

感谢。

2 个答案:

答案 0 :(得分:3)

设置:helpText.setMovementMethod(new ScrollingMovementMethod());

答案 1 :(得分:1)

像这样,

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



<TextView
       android:id="@+id/TextView_HelpText"
           android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:autoLink="all"
       android:isScrollContainer="true"
       android:textStyle="italic"
       android:drawablePadding="5px"
       android:textColorLink="@color/logo_color"
       android:linksClickable="true"
       android:fadingEdgeLength="25px"
       android:fadingEdge="vertical"
       android:scrollbars="vertical"
       android:padding="@dimen/help_text_padding"
       android:textSize="@dimen/help_text_size"
       android:scrollbarStyle="outsideOverlay"
       android:bufferType="spannable"
        android:textColor="#000000"></TextView>

</ScrollView>

也不建议使用“px”。使用“dip”代替fadingLength和padding。

相关问题