imagespan

How TextSize and LineSpace affects ImageSpan

守給你的承諾、 提交于 2019-12-11 06:25:38
问题 I want to measure ImageSpan with StaticLayout. to do this I use a simple code like below: SpannableStringBuilder content = new SpannableStringBuilder(); Spannable imageSpannable = getImageSpannable(); content.append(imageSpannable); StaticLayout layout = new StaticLayout(content, txt.getPaint(), txt.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1, lineSpace, false); txt is a TextView and lineSpace just a variable indicating txt line space. And getImageSpannable: private Spannable

TextView的日常使用技巧

断了今生、忘了曾经 提交于 2019-12-07 11:12:28
Textview 在日常开发工作中使用非常频繁,在这里简单总结一下其比较重要的用法。目标是设置textview的中一段文字的显示属性,例如指定文字要下划线显示(@XXX、#XXX#),文字替换成图片,文字加重、变色、变大等。 实现的基本思路都是将指定的文字找出来,然后用实现Spananble接口的子类覆盖,即可。 Spananble只是一个接口,它的继承关系是:Spananble->Spanned->CharSequence 因为Spannable继承于CharSequence接口,因而,TextView可以直接setText,Spannable的实现类:Editable, SpannableString, SpannableStringBuilder 。 Spannable中有提供public abstract void setSpan (Object what, int start, int end, int flags) 方法,来设置被替换部分要显示的样式 其中参数Object what 又必须是 android.text.style.CharacterStyle 的实现子类,就是它决定显示的样式,例如实现下划线的UrlSpan,实现改变字体颜色的ForegroundColorSpan,实现改变字体大小的AbsoluteSizeSpan,实现替换成图片的ImageSpan等

TextView with ImageSpan messes up line height

自古美人都是妖i 提交于 2019-12-04 10:53:29
I have a TextView filled with text that should contain some ImageSpan objects. The images can be taller than the normal line height which causes the following problem: if the image is the last object of a line, the following lines' height is correct if the last object is not an image, the following lines' height is set to the image-containing line's height Here is the correct situation: This is the wrong situation: What's more interesting is that if there's a new-line character in the text, the line height is good from that point on again. The TextView is just a pretty basic one: <TextView

ImageSpan not working on Android 5

孤街浪徒 提交于 2019-12-04 02:44:30
I have this function that works fine on Android 4.4.1, but breaks on 5.0+. public static SpannableStringBuilder prependImage(Drawable drawable, String text) { SpannableStringBuilder builder = new SpannableStringBuilder(" " + text); builder.setSpan(new ImageSpan(drawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return builder; } And I use it like this: class MyButton extends Button { // ... snip ... setText( prependImage( getDrawable(imageResource, color), getContext().getString(stringResource)), BufferType.SPANNABLE); Here is the getDrawable() method referenced above: private Drawable

How to use the Image(Stored Image of device) with Text on TextView Android?

我们两清 提交于 2019-11-30 13:56:04
问题 I am creating the chat app , in which i am getting the EMOJI from the server (IMAGE URLS). I am using this images(Emoji url) with text in my TextView by below lines of the code. String stringWithHtml = "Sample string with an <img src=\"http://MY_SERVER.emoji.s3.amazonaws.com/cf68/5794d5f7895fa10a8f8e1350/imgList/5794d5f7895fa10a8f8e136a.png\"></img>" + "<img src=\"http://MY_SERVER.emoji.s3.amazonaws.com/cf68/5794d5f7895fa10a8f8e1350/imgList/5794d5f7895fa10a8f8e135a.png\"></img>"+ "<img src=\

How to use the Image(Stored Image of device) with Text on TextView Android?

泪湿孤枕 提交于 2019-11-30 08:57:48
I am creating the chat app , in which i am getting the EMOJI from the server (IMAGE URLS). I am using this images(Emoji url) with text in my TextView by below lines of the code. String stringWithHtml = "Sample string with an <img src=\"http://MY_SERVER.emoji.s3.amazonaws.com/cf68/5794d5f7895fa10a8f8e1350/imgList/5794d5f7895fa10a8f8e136a.png\"></img>" + "<img src=\"http://MY_SERVER.emoji.s3.amazonaws.com/cf68/5794d5f7895fa10a8f8e1350/imgList/5794d5f7895fa10a8f8e135a.png\"></img>"+ "<img src=\"http://MY_SERVER.emoji.s3.amazonaws.com/cf68/5794d5f7895fa10a8f8e1350/imgList/5794d5f7895fa10a8f8e135b

Is there any way to insert an ImageSpan in a TextView without disrupting the text?

早过忘川 提交于 2019-11-29 09:14:22
It seems that in order to add an ImageSpan to a Spannable in Android, I have to actually replace some text with the Image. For example: Spannable span = new SpannableString("Foo imageplace Bar!"); Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 32,32); ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, 4, 14, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); This will replace "imageplace" with the image. Because I'm dealing with complex multi-span text and reiteration, it's a bit of a headache to insert meaningless text

Is there any way to insert an ImageSpan in a TextView without disrupting the text?

为君一笑 提交于 2019-11-27 23:38:04
问题 It seems that in order to add an ImageSpan to a Spannable in Android, I have to actually replace some text with the Image. For example: Spannable span = new SpannableString("Foo imageplace Bar!"); Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 32,32); ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, 4, 14, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); This will replace "imageplace" with the image. Because I'm

Align text around ImageSpan center vertical

本小妞迷上赌 提交于 2019-11-27 03:23:57
I have an ImageSpan inside of a piece of text. What I've noticed is that the surrounding text is always drawn at the bottom of the text line -- to be more precise, the size of the text line grows with the image but the baseline of the text does not shift upward. When the image is noticeably larger than the text size, the effect is rather unsightly. Here is a sample, the outline shows bounds of the TextView : I am trying to have the surrounding text be centered vertically with respect to the image being displayed. Here is the same sample with blue text showing the desired location: Here are the

Align text around ImageSpan center vertical

与世无争的帅哥 提交于 2019-11-26 10:28:59
问题 I have an ImageSpan inside of a piece of text. What I\'ve noticed is that the surrounding text is always drawn at the bottom of the text line -- to be more precise, the size of the text line grows with the image but the baseline of the text does not shift upward. When the image is noticeably larger than the text size, the effect is rather unsightly. Here is a sample, the outline shows bounds of the TextView : I am trying to have the surrounding text be centered vertically with respect to the