Search code examples
androidtextviewuniversal-image-loader

Load image into TextView's background


I have the following TextView layout:

<TextView
    android:layout_width="10dp"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:drawableTop="@drawable/ic_launcher" >

I inflate this layout in code, and want to use Android-Universal-Image-Loader to load the image into drawableTop. But, as I understand, there's no way to get backgroundTop's ImageView from TextView, thus I can't use AUIL. Is there any way to get ImageView for background, and if not, how should I modify the layout so that it will have ImageView but will look the same as the original layout?


Solution

  • Use a RelativeLayout with ImageView and TextView then manipulate ImageView

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_alignBottom="@+id/textView1"
            android:layout_alignLeft="@+id/textView1"
            android:layout_alignRight="@+id/textView1"
            android:layout_alignTop="@+id/textView1"
            android:src="@drawable/ic_launcher" />
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </RelativeLayout>