Search code examples
androidbackgroundtextviewlinestretched

Android: textView is added dynamicly. How to add this to specific line


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.


Solution

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