【问题标题】:Display view to right of text在文本右侧显示视图
【发布时间】:2014-06-30 12:22:21
【问题描述】:

我想显示文本(曲目标题)和文本右侧的视图。如下图所示。

视图(上面屏幕截图中的图像)应该始终可见。如果空间过多,则视图应显示在文本之后。如果没有足够的空间,文本应该被截断。

问题是:如果文本足够长,则视图不会显示或以较小的尺寸显示。

请不要推荐我使用带有drawableEnd 属性的文本视图,因为视图并不总是图像视图。

这是我使用的布局:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1">

    <TextView
        android:id="@+id/trackTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:ellipsize="end"
        android:text="@string/placeholderTrackTitle"
        android:textSize="@dimen/track_name_height"
        android:textColor="@color/queue_text_color"
        android:layout_weight="0"/>

    <ImageView
        android:id="@+id/downloadedIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_downloaded"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="@dimen/queue_horizontal_margin"
        android:layout_marginRight="@dimen/queue_horizontal_margin"
        android:layout_weight="1"
        android:contentDescription="@string/downloaded_icon_description"/>
</LinearLayout>

【问题讨论】:

  • 您希望显示文本和图像,但图像应始终在右侧,文本在左侧,如果文本太长则应截断,这就是你要找的吗?
  • @Goofy 差不多。我想要一个文本和一个视图(视图可能是也可能不是图像)。其他都是正确的。
  • 请在下面查看我的答案,它可能对您有所帮助
  • 你能告诉我在你的声明“视图并不总是图像视图”之类的文本之后必须显示什么类型的视图。
  • @Haresh 它可以是图像视图或圆形进度条。

标签: android android-layout


【解决方案1】:

在 TextView 上使用 maxWidth 属性并省略文本以防溢出。

编辑:或MaxLengthMaxLinesMaxEms,以更适合您的目的为准

【讨论】:

  • 这不是我预期的解决方案,但在这里最好。
【解决方案2】:

【讨论】:

  • 看起来这两个链接都与视图定位问题无关。
  • @Bobrovsky 在你的问题The issue is: if the text is long enough the view is not displayed or displayed in smaller size. 我已经回答了这个问题
  • 恐怕你错了。您建议使用 ellipsize 功能,但我已经在使用它了。
  • hmmmm,在这种情况下使用权重并修复视图大小并继续,这将解决您的问题
猜你喜欢
  • 2019-05-29
  • 2021-10-24
  • 1970-01-01
  • 2020-10-06
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多