繁体   English   中英

TextView不显示所有行吗?

[英]TextView not displaying all the lines?

这是TextView的XML布局:

<LinearLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ScrollView 
        android:id="@+id/scrollview1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:fillViewport="true">
<TextView
        android:id="@+id/tv1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.0"
        android:typeface="sans"
        android:layout_gravity="center_vertical|left"
        android:textSize="17sp" 
        />
</ScrollView>
</LinearLayout>

文本是从包含431行的.txt文件中获取的。 但是前81行不在屏幕范围内(位于屏幕顶部边缘之外)。 我究竟做错了什么?

读取.txt文件的代码:

    String l="";
    TextView two=(TextView)findViewById(R.id.tv1);
    InputStream is =getAssets().open("codes1.txt");
    InputStreamReader iz=new InputStreamReader(is);
    BufferedReader bis = new BufferedReader(iz);
    try {
        String text="";
        while((l=bis.readLine())!=null) {
            text=text+l+"\n";
        }
        two.setText(text);
        two.setMovementMethod(new ScrollingMovementMethod());
    } catch(Exception a) { Log.d("error is "+a.toString(),"error"); }

好的,所以内容在那里,尝试从TextView删除android:layout_gravity="center_vertical|left"并删除此行

two.setMovementMethod(new ScrollingMovementMethod()); 从您的java文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM