android - 相对布局 - 自动换行

标签 android android-imageview android-relativelayout android-wrap-content

我有以下代码 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/

相关文章:

Android list 错误

java - Android的表单验证库?

Android Google map APIv2 InfoWindow 和标记

android - 以编程方式在另一个布局中添加布局

android - 动态添加 View 到 Activity 布局

android - 使用 RelativeLayout 在 ListView 中重复 RatingBar wonkiness

android - 使用 RelativeLayout 添加页脚时出现问题

android - 如何使用cordova2.6的config.xml设置android启动画面

java - 如何使用句柄在 android 中缩放 View ?

java - 绩效十亿计数器