I've been creating Chips
like Gmail and most of the social android application for address.
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);
}
There are Chips
implemented as a Material design component:
Definition: material.io/design/components/chips.html#input-chips
Android lib: material.io/develop/android/components/chip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With