1

I have the following code snippet:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/collected_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/card_text_color"
        android:textSize="@dimen/card_headline_textsize"
        android:layout_marginBottom="@dimen/card_headline_marginBottom"
        android:text="Foo" />

    <ImageView
        android:id="@+id/collected_item_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxHeight="140dp"
        android:background="@android:color/holo_red_dark"
        android:adjustViewBounds="true"
        android:layout_below="@id/collected_item_title"
        android:layout_marginEnd="8dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/collected_item_image"
        android:layout_below="@id/collected_item_title"
        android:text="Foo"
        android:textColor="@color/card_text_color" />

</RelativeLayout>

I like to have the ImageView on the left and the second TextView either on the right of this image or unter the image, dependent on the size of the image. The image should grow, until it reaches a maximum height of 140dp.

How can I automatically wrap the text if the image get's too width? Unfortunately I have no idea at the moment how to do it. Yes I can do it programmatically, but I like to reach the goal only with xml.

The wrapping RelativeLayout doesn't have to be a RelativeLayout, if this behaviour is possible with an other layout.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Fabian
  • 825
  • 1
  • 8
  • 16

2 Answers2

2

It sounds like you need a FlowLayout. Android does not provide one out-of-the-box, but check out this answer. How can I do something like a FlowLayout in Android?

Community
  • 1
  • 1
chessdork
  • 1,999
  • 1
  • 19
  • 20
0

Thanks to the answer of chessdork, I found the flexbox layout of google. It gets provided by the following git repository. https://github.com/google/flexbox-layout

Fabian
  • 825
  • 1
  • 8
  • 16