0

I have already read this post: Making TextView scrollable on Android without success.

My app looks like this: enter image description here

Where the black space is a TextView. It is declared at the xml like this:

<TextView
android:id="@+id/consola"
android:layout_width="320px"
android:layout_height="333px"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:scrollbars = "vertical"
android:gravity="top|left" 
android:inputType="textMultiLine"
>
</TextView>

And my code takes text into the editText when a button is pressed, and writes a new line at the textView with that text. Code looks like:

public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final TextView miConsola = (TextView) findViewById(R.id.consola);
    miConsola.setMovementMethod(new ScrollingMovementMethod());

    final EditText lineaComando = (EditText) findViewById(R.id.linea_comando);
    final Button botonConectar = (Button) findViewById(R.id.boton_conectar);
    final Button botonEnviar = (Button) findViewById(R.id.boton_enviar);

    botonEnviar.setEnabled(false);

    botonConectar.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          // Intentaremos conectar por bluetooth aqui
            botonConectar.setEnabled(false);
            botonEnviar.setEnabled(true);
        }               
      });

    botonEnviar.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          // Enviamos el comando
            CharSequence comando = lineaComando.getText();
            miConsola.append(comando+"\r\n");
        }               
      });
    miConsola.append("Esto es una prueba\r\n");
    miConsola.append("Esto es otra prueba\r\n");


}

}

But when the text reaches the bottom of the TextView, it still writes a new line over the EditText, and if i go on, no scroll bar appear.

Any idea of what I'm doing wrong?

Community
  • 1
  • 1
Roman Rdgz
  • 11,378
  • 36
  • 110
  • 192

2 Answers2

1

put your text view in a vertical ScrollView.Set the height of the Scroll View some fixed height as you did for your text view.Then set wrap_content to your text view's width and height.

Rasel
  • 16,129
  • 6
  • 40
  • 50
1

Using hard-coded pixel values in your xml layout is not the best way. Use a relative layout and set the TextView to be above your EditText. I put my TextViews in ScrollViews also (using the relative layout above attribute to keep them in place).

Kevin King
  • 1,511
  • 11
  • 14