0

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?

alterionisto
  • 77
  • 1
  • 8

3 Answers3

8

You can use listener (ImageLoadingListener) for that. Put following code in onLoadingComplete(...)

void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    Drawable topImage = new BitmapDrawable(loadedImage);
    textView.setCompoundDrawablesWithIntrinsicBounds(null, topImage, null null);
}
nostra13
  • 12,377
  • 3
  • 33
  • 43
0
                TextView tv = (TextView) findViewById(R.id.TV);
                Drawable top = getResources().getDrawable(R.drawable.icon) ;
                tv.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null) ;
 //             tv.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
Arun C
  • 9,035
  • 2
  • 28
  • 42
0

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>
Arun C
  • 9,035
  • 2
  • 28
  • 42