android - I want to put a text and image in imageview -


i used bitmap crop image. draw text on image, want below image of same imageview. have seen using textview below image, requirement put text , image in single imageview.

my main class:

public class mainactivity extends activity {  static imageview imageview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      imageview=(imageview)findviewbyid(r.id.imageview1);      bitmap bitmap=bitmapfactory.decoderesource(getresources(), r.drawable.images_1);             imageview.setimagebitmap(getcirclebitmap(bitmap));  }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }   public static bitmap getcirclebitmap(bitmap bitmap) {      //crop circle      bitmap output;     //check if rectangular image     if (bitmap.getwidth() > bitmap.getheight()) {         output = bitmap.createbitmap(bitmap.getheight(), bitmap.getheight(), config.argb_8888);     } else {         output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getwidth(), config.argb_8888);     }     canvas canvas = new canvas(output);      float r = 0;      if (bitmap.getwidth() > bitmap.getheight()) {         r = bitmap.getheight() / 2;     } else {         r = bitmap.getwidth() / 2;     }      final paint paint = new paint();     final rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight());      paint.setcolor(color.white);      paint.setantialias(true);     canvas.drawargb(0, 0, 0, 0);      canvas.drawcircle(r, r, r, paint);     paint.setxfermode(new porterduffxfermode(mode.src_in));     canvas.drawbitmap(bitmap, rect, rect, paint);      rect bounds = new rect();     int x = (bitmap.getwidth() - bounds.width())/2;     int y = (bitmap.getheight() + bounds.height())/2;       canvas.drawtext("hii",x,y, paint);      return output; } 

in xml file:

<imageview     android:id="@+id/imageview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/textview1"     android:layout_below="@+id/textview1"     android:layout_marginleft="26dp"     android:layout_margintop="52dp"     android:src="@drawable/image" /> 

any appreciated. thank

a safe way create image , add it's text under (in photoshop example) , save png , use it. won't use space , can have own font style etc. previous answers , can use them well


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -