Skip to content Skip to sidebar Skip to footer

Android Add Image To Text (in Text View)?

first post here=) I've been looking for this answer and haven't been able to find it. What I want to do is have some text, then add a image, then rest of text. For example:

Solution 1:

I think you are looking for the Spannable interface, By using this you can add images to a text view.

This link might help.

enter image description here

Solution 2:

your best option is to create your own view, and to override the onDraw() method using canvas.drawText() for text, and canvas.drawBitmap() for images.

See the Canvas doc : http://developer.android.com/reference/android/graphics/Canvas.html

Here is an example which draw some text at the center of the screen :

publicclassOverlayViewextendsView {

publicOverlayView(final Context context) {
    super(context);
}

/**
 * Draw camera target.
 */@OverrideprotectedvoidonDraw(final Canvas canvas) {

    // view sizeintwidth= getWidth();
    intheight= getHeight();

    floatsquare_side= height - width * 0.8f; // size of the target squarePaintpaint=newPaint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);

    // text size is 5% of the screen height
    paint.setTextSize(height * 0.05f);

    // draw message depending of its widthStringmessage= getResources().getString(R.string.photo_target_text);

    floatmessage_width= paint.measureText(message);

    paint.setColor(getResources().getColor(R.color.color_foreground));
    canvas.drawText(message, (width - message_width) / 2,
            (height - square_side) / 4, paint);

    super.onDraw(canvas);
}

}

Solution 3:

as I know, there's no way to do it.

but when you use webview and generated html you can do simillar one.

generate html from your contents, and load it to webview, set webview settings to no zoom control.

Solution 4:

This can be done with image getter: Html.ImageGetter

You will have to use HTML tags for each image.

Solution 5:

< string name="text" > "Hi there, this is the photo [img src=img.jpge/] , hope you like it. < / string>

Add this in to your String and it will work

Post a Comment for "Android Add Image To Text (in Text View)?"