问题
I'm trying to achieve the following view in image programmatically. I am adding text view to relative layout dynamically. My problem is text view are added as required to right of each text view added prior. But after one row completion other text views are hidden due to the size of screen. How to add other remaining text view to next line after they added in one line. Whether my approach is wrong to achieve this. Please guide me. Thanks.
Here is code :
RelativeLayout llTags = (RelativeLayout)res.findViewById(R.id.layout_tags);
for (int i = 0; i < arrTags.size(); i++) {
View view = (getActivity()).getLayoutInflater().inflate(R.layout.item_tags, null);
tvTag = (TextView) view.findViewById(R.id.tv_tags);
tvTag.setText(arrTags.get(i));
view.setId(i+1);
RelativeLayout.LayoutParams lpFirst = new
RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
if(i!=0){
lpFirst.addRule(RelativeLayout.RIGHT_OF,view.getId()-1);
lpFirst.setMargins(5,0,0,0);
}
llTags.addView(view, i, lpFirst);
}

回答1:
Finally after much googling got the solution from here :
https://github.com/ApmeM/android-flowlayout
Need to create custom flow layout instead of relative layout used.Custom flow layout will adjust child views accordingly in rows.
来源:https://stackoverflow.com/questions/17878741/adding-text-views-in-multiple-rows-in-relative-layout-programmatically