添加的TextView的LinearLayout中像芯片一样的Gmail地址建议 [英] Adding TextView in LinearLayout like chips same as Gmail address suggestion

查看:121
本文介绍了添加的TextView的LinearLayout中像芯片一样的Gmail地址建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建芯片如Gmail和大多数社交Android应用程序的地址。

我一直在追加的LinearLayout 值是工作的罚款,只要它小于设备宽度。只要它的长度超过设备宽度它变得混杂起来。

如何在每一个enviornment一个preserve相同的行为?

预期的行为:

我得到了什么

code段:

 <的LinearLayout
        机器人:ID =@ + ID / chipsBoxLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=横向
        >
<! - 布局增添筹码,如Gmail应用程序 - >
< / LinearLayout中>
 


  LinearLayout.LayoutParams PARAMS =新LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1);
params.setMargins(5,0,5,0);

迭代器<联系与GT; iterContacts = contacts.iterator();
而(iterContacts.hasNext())
{
  联系方式联系方式= iterContacts.next();
  TextView的T =新的TextView(MainActivity.this);
  t.se​​tLayoutParams(PARAMS);
  t.se​​tPadding(5,5,5,5);
  t.se​​tText(contact.getContactName());
  t.se​​tTextColor(Color.WHITE);
  t.se​​tBackgroundColor(Color.BLUE);
  chipsBoxLayout.addView(T);
}
 

解决方案

根据Rethinavel皮莱,

的FlowLayout 将按预期在增加的看法,我会自己,如果它里面的的FlowLayout <补充容纳/ code>。

code段:

 &LT; com.FlowLayout
            机器人:ID =@ + ID / chips_box_layout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:重力=开始
             &GT;
&LT; /com.FlowLayout>
 


 的FlowLayout chipsBoxLayout;
chipsBoxLayout =(的FlowLayout)findViewById(R.id.chips_box_layout);


FlowLayout.LayoutParams PARAMS =新FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_CONTENT,FlowLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5,5,5,5);

迭代器&LT;联系与GT; iterContacts = contacts.iterator();
而(iterContacts.hasNext())
{
  联系方式联系方式= iterContacts.next();
  TextView的T =新的TextView(MainActivity.this);
  t.se​​tLayoutParams(PARAMS);
  t.se​​tPadding(5,5,5,5);
  t.se​​tText(contact.getContactName());
  t.se​​tTextColor(Color.WHITE);
  t.se​​tBackgroundColor(Color.BLUE);
  chipsBoxLayout.addView(T);
}
 

I've been creating Chips like Gmail and most of the social android application for address.

Que

I've been appending values in LinearLayout is working fine as long as it less than device width. As soon as it's length more than device width it gets jumble up.

How can a preserve same behaviour in every enviornment?

Expected Behaviour :

What i got

Code Snippet:

<LinearLayout
        android:id="@+id/chipsBoxLayout" 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >
<!--Layout to add Chips like Gmail application-->
</LinearLayout>


LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,1);
params.setMargins(5, 0, 5, 0);

Iterator<Contact> iterContacts = contacts.iterator();
while(iterContacts.hasNext()) 
{   
  Contact contact = iterContacts.next();
  TextView t = new TextView(MainActivity.this);
  t.setLayoutParams(params);
  t.setPadding(5, 5, 5, 5);
  t.setText(contact.getContactName());
  t.setTextColor(Color.WHITE);
  t.setBackgroundColor(Color.BLUE);
  chipsBoxLayout.addView(t);
}

解决方案

As per Rethinavel Pillai ,

FlowLayout works as expected in adding views which i will accomodate by itself if it's added inside FlowLayout.

Code Snippet:

<com.FlowLayout
            android:id="@+id/chips_box_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="start"
             >
</com.FlowLayout>


FlowLayout chipsBoxLayout;
chipsBoxLayout = (FlowLayout)findViewById(R.id.chips_box_layout);


FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);

Iterator<Contact> iterContacts = contacts.iterator();
while(iterContacts.hasNext()) 
{   
  Contact contact = iterContacts.next();
  TextView t = new TextView(MainActivity.this);
  t.setLayoutParams(params);
  t.setPadding(5, 5, 5, 5);
  t.setText(contact.getContactName());
  t.setTextColor(Color.WHITE);
  t.setBackgroundColor(Color.BLUE);
  chipsBoxLayout.addView(t);
}

这篇关于添加的TextView的LinearLayout中像芯片一样的Gmail地址建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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