以编程方式在相对布局中的多行中添加文本视图 [英] Adding Text views in multiple rows in Relative layout programmatically

查看:44
本文介绍了以编程方式在相对布局中的多行中添加文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式实现以下图像视图. 我正在动态地将文本视图添加到相对布局. 我的问题是根据需要将文本视图添加到每个先前添加的文本视图的右侧. 但是在一行完成后,由于屏幕的大小,其他文本视图将被隐藏. 在一行中添加其他剩余文本视图后,如何将它们添加到下一行. 我的方法是否错误实现了这一目标.请指导我.谢谢.

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.

这是代码:

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

推荐答案

最后,经过大量的搜索,从这里得到了解决方案:

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.

这篇关于以编程方式在相对布局中的多行中添加文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆