Android Add image to text (in text View)?

只谈情不闲聊 提交于 2019-11-30 04:50:33

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

This link might help.

ndeverge

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 :

public class OverlayView extends View {

public OverlayView(final Context context) {
    super(context);
}

/**
 * Draw camera target.
 */
@Override
protected void onDraw(final Canvas canvas) {

    // view size
    int width = getWidth();
    int height = getHeight();

    float square_side = height - width * 0.8f; // size of the target square

    Paint paint = new Paint();
    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 width
    String message = getResources().getString(R.string.photo_target_text);

    float message_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);
}

}

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.

Lumis

This can be done with image getter: Html.ImageGetter

You will have to use HTML tags for each image.

Prassanna Kumar
< 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!