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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…