Android TextView 안에 이미지 추가

android 2011. 10. 13. 11:25 Posted by jiddong
  1.     /**
  2.      *  텍스트 앞에 이미지가 추가 된다
  3.      *
  4.      * @param tv
  5.      * @param text
  6.      */
  7.     private void setTitle(TextView tv, String text, boolean isAdult) {
  8.         if(!isAdult) {
  9.             tv.setText(text);
  10.         } else {
  11.             tv.setText(Html.fromHtml("<img src=\"이미지름\"/>" + text, new ImageGetter()null));
  12.  
  13.         }
  14.     }
  15.  
  16.     private final String PACKAGE_NAME = "패키지명";
  17.  
  18.     public class ImageGetter implements Html.ImageGetter {
  19.  
  20.         @Override
  21.         public Drawable getDrawable(String source) {
  22.             int nID = 0;
  23.             nID = getResources().getIdentifier(source, "drawable", PACKAGE_NAME);
  24.             Drawable d = getResources().getDrawable(nID);
  25.             d.setBounds(00, d.getIntrinsicWidth() + 6, d.getIntrinsicHeight());
  26.             return d;
  27.         }
  28.     }