我有以下代码 fragment :
<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>
我喜欢将 ImageView 放在左侧,将第二个 TextView 放在该图像的右侧或图像下方,具体取决于图像的大小。 图像应该会增长,直到达到最大高度 140dp。
如果图像太宽,我如何自动换行文本? 不幸的是,我现在不知道该怎么做。 是的,我可以通过编程方式完成,但我喜欢只使用 xml 来实现目标。
包装 RelativeLayout 不必是 RelativeLayout,如果其他布局可以实现此行为。
最佳答案
听起来您需要一个FlowLayout
。 Android 不提供开箱即用的功能,但请查看此答案。 How can I do something like a FlowLayout in Android?
关于android - 相对布局 - 自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594653/