使用TextView和ImageView的RelativeLayout

时间:2018-01-10 08:14:53

标签: android android-layout textview imageview android-relativelayout

我想为我的spannable视图创建一个布局。 (在EditText中查看) 它由ImageView和TextView组成。

它应该是这样的:

enter image description here

到目前为止我所拥有的:

<?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>

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

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

1 个答案:

答案 0 :(得分:1)

您可以在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"> <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>

{{1}}

现在查看您的文字与图片一起显示。 (我把我自己的形象换成了你的) enter image description here