Search code examples
androiduser-interfacetagssmsandroid-controls

Android UI control like tag control


I want to know how to get a control that contains list of strings arranged as in an image bellow.

enter image description here

you can see the strings strings added in random way based on its width

I tried to use normal textview with inside a linear or relative layout with but it didnt work. Can you pleae tell me the best practice to have a control that I pass to it a list of strings and it shows them like the image bellow ?


Solution

  • This can be done using a flow layout and toggle buttons inside it. A good flow layout is available here. And the toggle buttons will need a Selector drawable to give it the proper checked/unchecked appearance.

    Here is a selector example:

    <?xml version="1.0" encoding="utf-8"?>
    

    <item android:drawable="@drawable/rect_tag_checked" android:state_checked="true"></item>
    <item android:drawable="@drawable/rect_tag_normal" android:state_checked="false"></item>
    <item android:drawable="@drawable/rect_tag_normal"></item>