0

所以我试图将一个文本视图放在填充父级的图像的左侧。任何想法如何在 XML 中做到这一点?有什么方法可以将带有 witdh 200dp 和高度 300dp 的 textview 放在父级的右上角?

这是我左侧图像视图的代码:

        <TextView
        android:id="@+id/display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="200dp"
        android:height="300dp"
        android:gravity="left"
        android:background="#00ffffff"
        />

请注意,我是新手

4

3 回答 3

0

如果我理解正确,您是否想在图像顶部“叠加”文本视图?

IE 图像占据整个父视图,文本视图与图像的上边缘和左边缘对齐。

如果是这种情况,您可能想要类似的东西:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
    <ImageView
      android:id="@+id/superawesomeimage"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@drawable/photoofmyholiday" />

     <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@id/superawesomeimage"
      android:layout_alignRight="@id/superawesomeimage"/>
</RelativeLayout>

这应该会沿着图像的(默认情况下为顶部)生成一个 textView,与图像容器的图像宽度相匹配(为了使图像完全占据图像视图,您需要指定一个我认为的比例(可能是 fitXY)。

我可能对这里的关键字/语法有点不满意。我只是在脑海中输入它,但你明白了一般的想法。

需要注意的重要事项是 TextView/ImageView 的顺序(它决定了谁在谁之上)和 TextView 布局对齐。使用相对布局,您可以相对于其他视图定位.. 因此设置左对齐和右对齐图像将使文本视图的左右边缘与图像视图的左右边缘对齐。希望有帮助。玩得开心!

于 2013-07-03T06:27:46.297 回答
0

我不确定你想在哪里对齐,但如果你想在右边对齐,你可以在RelativeLayout中使用它:

android:layout_alignParentRight="true"
于 2013-07-03T01:11:55.290 回答
0

在文本视图中使用以下属性:

android:layout_toLeftOf="@id/your_image_view_id"

只需确保您的 ImageView 在 TextView 之前的 xml 中声明并给它一个 id(例如,android:id="@+id/your_image_view_id")。

于 2013-07-03T01:15:52.617 回答