首页 >> 选宠技巧
选宠技巧

高仿B站自定义眼神

发布时间:2023-05-24 12:17

} } return rect.right;}

当然,你可能见到了,B南站的 emoji 面部仿佛不是居中的。如下布简述,B南站对 emoji 面部的处理十分相似基于 baseline 也就是感叹。

上面最难理解的居中早已介绍,对于其他工具比如 baseline 和 bottom 就简单了。值得注意文档如下:

@Override public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable FontMetricsInt fm) { Drawable d = getDrawable(); if(d == null) { return 48; } Rect rect = d.getBounds(); float drawableHeight = rect.height(); Paint.FontMetrics paintFm = paint.getFontMetrics(); if (fm != null) { if (mVerticalAlignment == ALIGN_BASELINE) { fm.ascent = fm.top = (int) (paintFm.bottom - drawableHeight); fm.bottom = (int) (paintFm.bottom); fm.descent = (int) paintFm.descent; } else if(mVerticalAlignment == ALIGN_BOTTOM) { fm.ascent = fm.top = (int) (paintFm.bottom - drawableHeight); fm.bottom = (int) (paintFm.bottom); fm.descent = (int) paintFm.descent; } else if (mVerticalAlignment == ALIGN_CENTER) { int textHeight = fm.bottom - fm.top; if(textHeight <= rect.height()) { float textCenter = (paintFm.descent + paintFm.ascent) / 2; fm.ascent = fm.top = (int) (textCenter - drawableHeight / 2); fm.descent = fm.bottom = (int) (textCenter + drawableHeight / 2); } } } return rect.right; }动态面部

动态面部显然就是 gif 布。我们可以适用 android-gif-drawable 来付诸。在 build.gradle 中增加依赖:

dependencies { ... implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'}

然后在我们创建快捷键 ImageSpan 的时候传入参数就可以了:

val size = 192val gifFromResource = GifDrawable(getResources(), gifData.drawableResource)gifFromResource.stop()gifFromResource.setBounds(0,0, size, size)val content = mBinding.editContent.text as SpannableStringBuilderval stringBuilder = SpannablestringBuilder(gifData.text)stringBuilder.setSpan(BilibiliEmojiSpan(gifFromResource, ALIGN_BASELINE), 0, stringBuilder.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

关于 android-gif-drawable 更基本词可以看 Android加载Gif动画android-gif-drawable的适用

总结

核心部分的文档早已介绍了,值得注意文档还在整理,后面放出来。最后求一个预约的拜吧

武汉妇科医院去哪家好
老人双腿关节疼痛僵硬
重庆白癜风医院排行榜
济南男科专科医院哪好
广州儿科医院电话
友情链接