2

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);           
}             

enter image description here

2
  • You just want to display TextView rows, one under the other? Commented Jul 26, 2013 at 10:21
  • @Jahckyto yes but textview depends on array of tags availabe. how to decide how many text views in one row. Commented Jul 26, 2013 at 10:26

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.