0

How to recognize when there is no more space in the screen of the device, so the view is added in the next line. Something like this:

1]

And I got this:

enter image description here

with this xml:

<LinearLayout
        android:orientation="horizontal"
        android:padding="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/tournament_client"
            android:textSize="@dimen/text_small_p"
            android:textColor="@color/grey_line"
            android:background="@color/black_10"
            android:text="Lorem Ipsum"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
Alejandro Cumpa
  • 2,118
  • 1
  • 24
  • 45

1 Answers1

0

I solve this using FlowLayout as Ertyguy said, works like charm:

with this in XML:

<com.theapplabperu.hazfutbol.Utils.FlowLayout
            android:id="@+id/layout_characteristics"
            android:paddingTop="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:layout_marginBottom="10dp"
            android:layout_width="match_parent"
            android:background="@color/white"
            android:orientation="vertical"
            android:layout_height="wrap_content">

And a Loop like this to add the views:

for (String caracteristics : myPlayer.getCaracteristics())
                {
                    i = i+1;
                    TextView tv = new TextView(myContext);
                    tv.setText(caracteristics);
                    tv.setId(i + 20);
                    tv.setPadding(10, 10, 10, 10);
                    tv.setTextSize(14);
                    tv.setTextColor(myContext.getResources().getColor(R.color.gray_tags));
                    tv.setBackgroundDrawable(getDrawable(R.drawable.tags_shape));    
                    FlowLayout.LayoutParams layoutParams = new  FlowLayout.LayoutParams(30, 15);
                    tv.setLayoutParams(layoutParams);
                    lnrGameChars.addView(tv);
                }
Alejandro Cumpa
  • 2,118
  • 1
  • 24
  • 45