I add textview'shki to LinearLayout like this:

linearLayout = (LinearLayout) findViewById(R.id.ololo); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); TextView textView = new TextView(messages.this); textView.setGravity(Gravity.RIGHT); //textView.setBackgroundResource(R.color.background_message_from); //textView.setText(message_enc_from_key); ////textView.setText(decrypt(hex2Byte(message_enc_from_key), private_key_my)); textView.setText(date_time); textView.setTextSize(20); linearLayout.addView(textView, params); 

Everything works without complaints, but here’s how I add a few more textviews after adding a few textviews, but only to the beginning of LinearLayout? because the method:

 linearLayout.addView(textView, params); 

adds them to the end.

  • textView.setGravity(Gravity.LEFT); - Suvitruf
  • setGravity and where is it? - Nikola Krivosheya

1 answer 1

Add by specifying an index like this:

 public void addView(View child, int index) 

those. in your case

 linearLayout.addView(view, 0);