1

I have 5 textViews which are added dinamicly but each textViews covers others. How to add each textView to specific line?

for(int z=0;z<c;z++){
    TextView lastHour = new TextView(projectActivity.this);
    lastHour.setPadding(5,z*35,0,0); // it currently allows me to see each textView in other line
    lastHour.setText("text"+z);                 
    relative_layout_for_last.addView(lastHour);
}

When I use setPadding, background for textView is stretched. I just want to add each textView in other line than previous textViews.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
aptyp
  • 251
  • 1
  • 6
  • 19
  • maybe the background of the layout that contain the textviews is streched, not the textviews background – mihail Dec 23 '11 at 11:15

4 Answers4

2
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
             50, (LayoutParams.WRAP_CONTENT));
        lp.leftMargin=5;
or(int z=0;z<c;z++){
    TextView lastHour = new TextView(projectActivity.this);
    lastHour.setPadding(5,z*35,0,0); // it currently allows me to see each textView in other line
    lastHour.setText("text"+z);    
    lastHour.setLayoutParams(lp);             
    relative_layout_for_last.addView(lastHour);
}

like this you can add own layout parameter as like you did in XML and set the text view approximately in your view.

Karthi
  • 13,624
  • 10
  • 53
  • 76
1

You could wrap them in a linear layout and set the orientation to vertical.

http://developer.android.com/reference/android/widget/LinearLayout.html

If you need any code snippets, please ask. I am in a bit of a hurry here;)

Bram
  • 4,533
  • 6
  • 29
  • 41
0

Padding won't do what you want. It will just increase the space between the top and the content. Either add them to a LinearLayout with vertical orientation, like Bram said, or if you're willing to keep your RelativeLayout, add a layout_below constraint specifying the id of your view on top.

jcxavier
  • 2,232
  • 1
  • 15
  • 24
0

You should use a LinearLayout to surround your TextViews. The orientation of the layout should be vertical.

If you need to stick with the RelativeLayout you should add this:

layoutParams.addRule(RelativeLayout.BELOW, theTextViewAbove.getId());
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150