vergil corleone
vergil corleone

Reputation: 1111

TextView not displaying all the lines?

This is the XML layout for the TextView:

<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>

The text is being sourced from a .txt file containing 431 lines. But the first 81 lines are out of the screen ( off the top edge of the screen). What am I doing wrong?

The code reading the .txt file:

    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"); }

Upvotes: 0

Views: 101

Answers (1)

Emil Adz
Emil Adz

Reputation: 41129

Ok, so the content is there, try to remove android:layout_gravity="center_vertical|left" from the TextView and remove this line

two.setMovementMethod(new ScrollingMovementMethod()); from your java file.

Upvotes: 1

Related Questions