Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding TextView in LinearLayout like chips same as Gmail address suggestion

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 :

Expected Behaviour

What i got

enter image description hereenter image description here

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);
}
like image 453
Vikalp Patel Avatar asked Apr 22 '14 10:04

Vikalp Patel


1 Answers

There are Chips implemented as a Material design component:

enter image description here

Definition: material.io/design/components/chips.html#input-chips

Android lib: material.io/develop/android/components/chip

like image 164
Francis Avatar answered Sep 19 '22 15:09

Francis