1

I am creating an android app, and I have to display for example 10 textviews - one next to each other etc., doesn't matter in how many rows, just do it automatically. Something like in this image:

enter image description here

Which layout should I use? I tried Gridlayout and gridview, but somehow I am not able to achieve such behavior. Any ideas?

Thanks!

qkx
  • 2,383
  • 5
  • 28
  • 50

2 Answers2

0

I would suggest you use a single texView for this unless you wish to give different UI design to every text like text color, background, font style etc.
If you are not aware of number of texts you may include use a single textView and set text to it your concatenated full text.
You text view should support multiple lines and you may also set a max limit to number of lines....
Example code:

      <TextView 
        android:id="@+id/tvMyText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:singleLine="false" 
        android:maxLines="5"
        android:textColor="@color/black"
        android:textSize="14sp" />

        String finalText = "";
        String[] yourData =  // string your containing all texts
        for ( String text : yourData ) {
            finalText = text + " "; // add space after every text
        }
        TextView tvText = (TextView) view.findViewById( R.id.tvMyText );
        tvText.setText( finalText );   

I'm not sure if this solution would work perfectly for your requirements... but you may just give it a thought.

Zeba
  • 3,041
  • 1
  • 28
  • 39
0

Hello here is example using custom Library which acts like List GitHubLibrary TagLayout

  • Sample Code:-

mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });

-- this will dynamically set your textview as per size of text in array

Hardy
  • 2,576
  • 1
  • 23
  • 45