0

May be this question already asked by another member but i won't found any answer for my question.

My question is How can i resize and rearrange textview according to text. Please take a look at image enter image description here

This kind of view used in Gmail app for sender email id and in "Android L" its known as "Chips" android Chips

Here i want to display 3 textview into sliding menu. these 3 textview are inside relative layout. Idea is if 1st textview text is long ("Swift" textview is something like "microsoft office" than "objective c " textview will be displayed below 1st textview "Microsoft office" and if first and second can share 1st line space than it will be displayed one after another.)

I tried AutoResizeTextView but it only resize font and it set textview height according to width so it not look good in terms of UI.

Any suggestion is appreciated

Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77
  • this is not single textview it may be custom or multiple textview if this android activity than you can get view hierarchy from DDMS – MilapTank Oct 16 '14 at 13:15
  • @andruboy yes i know its not single textview..please read my question, In my question i mention about 3 textview..and I know we can get it by some custom view but million dollar question is how? – Swap-IOS-Android Oct 16 '14 at 13:25
  • It is similar to chips from android L http://www.google.com/design/spec/components/chips-tokens.html (or at least the way they are viewed). Also, gmail app has something similar. Maybe AOSP would help? – dominik4142 Oct 16 '14 at 13:36
  • @Swap-IOS-Android here is a nasty (but I assume working solution) http://stackoverflow.com/questions/2961777/android-linearlayout-horizontal-with-wrapping-children. Add children dynamically, track their size and if child to be added wont fit, add new line (or control its position differently) and place below. – dominik4142 Oct 16 '14 at 13:49
  • @dominik4142 i found this https://github.com/blazsolar/FlowLayout – Swap-IOS-Android Oct 16 '14 at 14:21

2 Answers2

1

Try this https://github.com/RanaRanvijaySingh/AdjustableLayout . What i did is create a new layout that extends linear layout and overridden addView() and removeView() function. This layout will allow you to add your own View (Layout) in horizontal orientation. The view keeps on adding until it exceeds the width you have defined for the layout, then view is automatically added to next line.

The view in red is custom layout with Imageview - Textview - Imageview

enter image description here

Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54
0

I found one very good Library called FlowLayout which take care of everything.. FlowLayout link

Into my Relative layout

<com.test.FlowLayout
        android:id="@+id/chips_box_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="start"
         >

chipsBoxLayout = (FlowLayout)keyword_layout.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);

        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Java");
        arrayList.add("Objective c");
        arrayList.add("Swift");
        for(int i = 0; i<3; i++)
        {
          TextView t = new TextView(context);
          t.setLayoutParams(params);
          t.setPadding(5, 5, 5, 5);
          t.setText(arrayList.get(i));
          t.setTextColor(Color.BLACK);
          t.setBackgroundColor(Color.WHITE);
          chipsBoxLayout.addView(t);
        }

and it works, Thank you @dominik4142 to give me hint about chips.

Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77