这是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"); }
答案 0 :(得分:1)
好的,所以内容就在那里,尝试从android:layout_gravity="center_vertical|left"
删除TextView
并删除此行
two.setMovementMethod(new ScrollingMovementMethod());
。