问题描述
我已经创建芯片
如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.setLayoutParams(PARAMS);
t.setPadding(5,5,5,5);
t.setText(contact.getContactName());
t.setTextColor(Color.WHITE);
t.setBackgroundColor(Color.BLUE);
chipsBoxLayout.addView(T);
}
根据Rethinavel皮莱,
的FlowLayout 将按预期在增加的看法,我会自己,如果它里面的的FlowLayout 。
code段:
< com.FlowLayout
机器人:ID =@ + ID / chips_box_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:重力=开始
>
< /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);
迭代器<联系与GT; iterContacts = contacts.iterator();
而(iterContacts.hasNext())
{
联系方式联系方式= iterContacts.next();
TextView的T =新的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);
}
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地址建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!