RelativeLayout 与 TextView 和 ImageView

RelativeLayout with TextView and ImageView

我想为我的可跨越视图创建一个布局。 (在 EditText 里面查看) 它由一个ImageView和一个TextView组成。

它应该是这样的:

我目前拥有的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:padding="0dp">
    <ImageView
        android:id="@+id/closeImg"
        android:layout_width="28dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/closecross" />
    <TextView
        android:id="@+id/remarkText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="this text will not be shown :("
        android:layout_toLeftOf="@+id/closeImg"
        android:gravity="center" />
</RelativeLayout>

设计器显示正确,但在运行时我看不到任何文本。我是在代码中分配文本还是直接在布局中分配文本

如何显示,就像我在上图中显示的那样?

您可以在 textview 中使用 drawableRight

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="0dp">
<TextView
    android:id="@+id/remarkText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:padding="5dp"
    android:drawableRight="@drawable/closecross"
    android:drawableEnd="@drawable/closecross"
    android:text="this text will not be shown :("
    android:layout_toLeftOf="@+id/closeImg"
    android:gravity="center" />
</RelativeLayout>

现在您的文字与图片一起显示了。 (我已经把我自己的形象换成了你的)