簡體   English   中英

具有TextView和ImageView的RelativeLayout

[英]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>

現在看,您的文本與圖像一起可見。 (我放了我自己的圖像,只是用您的圖像替換了) 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM