Android layout 要将布局\u中心水平与布局\u至水平混合使用吗

Android layout 要将布局\u中心水平与布局\u至水平混合使用吗,android-layout,Android Layout,我正在努力满足一个特定的布局要求 我想要一个它居中的文本视图。它是单行,如果文本太长,则使用省略号。在同一行的右边,我想要一个小的图像视图。ImageView的存在不得影响TextView认为布局的水平中心。因此,尽管文本可能居中,但中心线右侧的可用空间实际上少于其左侧 在RelativeLayout中,可以使用的直观方式是: <ImageView android:id="@+id/image_view_id" android:layout_width="wrap_content"

我正在努力满足一个特定的布局要求

我想要一个它居中的文本视图。它是单行,如果文本太长,则使用省略号。在同一行的右边,我想要一个小的图像视图。ImageView的存在不得影响TextView认为布局的水平中心。因此,尽管文本可能居中,但中心线右侧的可用空间实际上少于其左侧

在RelativeLayout中,可以使用的直观方式是:

<ImageView
  android:id="@+id/image_view_id"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentRight="true" />

<TextView
  android:id="@+id/text_view_id"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toLeftOf="@id/image_view_id"
  android:layout_centerHorizontal="true"
  android:singleLine="true"
  android:ellipsize="middle" />
但这不起作用,因为您不能同时拥有android:layout_-toLeftOf和android:layout_-center。它的行为就像android:layout\u centerHorizontal不在那里一样


我还尝试过在android上使用LinearLayout:Layou-gravity,但没有成功。有可能吗?

事实证明,接近我想要实现的目标非常简单:

<ImageView
  android:id="@+id/image_view_id"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentRight="true" />

<TextView
  android:id="@+id/text_view_id"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_toLeftOf="@id/image_view_id"
  android:layout_marginLeft="@dimen/size_of_image_view"
  android:singleLine="true"
  android:gravity="center"
  android:ellipsize="middle" />

使用android:gravity=center和android:layout\u width=match\u parent将文本置于可用空间的中心。它不是完美的,因为左边的边缘可以使文本在整个布局中居中,从而从其左端占用一点空间,但对于我来说已经足够好了。

你能提供你想要做什么的精确图形说明吗?