【问题标题】:Relative Layout - Automatic wrapping相对布局 - 自动换行
【发布时间】:2016-06-02 14:25:23
【问题描述】:

我有以下代码sn-p:

<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,如果其他布局可以实现此行为。

【问题讨论】:

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


    【解决方案1】:

    听起来您需要FlowLayout。 Android 不提供开箱即用的功能,但请查看此答案。 How can I do something like a FlowLayout in Android?

    【讨论】:

      【解决方案2】:

      感谢chessdork的回答,找到了google的flexbox布局。 它由以下 git 存储库提供。 https://github.com/google/flexbox-layout

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-26
        • 1970-01-01
        • 2019-12-12
        • 2017-10-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多