本文整理汇总了Java中android.text.style.ImageSpan.ALIGN_BOTTOM属性的典型用法代码示例。如果您正苦于以下问题:Java ImageSpan.ALIGN_BOTTOM属性的具体用法?Java ImageSpan.ALIGN_BOTTOM怎么用?Java ImageSpan.ALIGN_BOTTOM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.text.style.ImageSpan
的用法示例。
在下文中一共展示了ImageSpan.ALIGN_BOTTOM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setText
/** 显示文本和表情 */
public static void setText(TextView textView, String text) {
Context context = textView.getContext();
Resources resources = context.getResources();
SpannableString ss = new SpannableString(text);
// 正则表达式: [高兴]
Pattern p = Pattern.compile("\\[([A-Za-z\u4E00-\u9FA5]+)\\]");
Matcher matcher = p.matcher(ss);
while (matcher.find()) {
// 匹配到一个表情字符串
String emoji = matcher.group();
// 过滤非表情符,比如: [xxx]
if (EMOJI_DATAS.containsKey(emoji)) { // 是表情才处理
// System.out.println("----------" + emoji);
// 指定了一张图片
Bitmap bitmap = BitmapFactory.decodeResource(resources, EMOJI_DATAS.get(emoji));
bitmap = Global.createBitmap(bitmap, Global.dp2px(20)); // 图片的宽高为20dp
ImageSpan span = new ImageSpan(context, bitmap, ImageSpan.ALIGN_BOTTOM);
int start = matcher.start();
int end = matcher.end();
ss.setSpan(span, start, end, 0);
}
}
textView.setText(ss);
}
示例2: replaceEmoticons
public static void replaceEmoticons(Context context, Editable editable, int start, int count) {
if (count <= 0 || editable.length() < start + count)
return;
CharSequence s = editable.subSequence(start, start + count);
Matcher matcher = EmojiManager.getPattern().matcher(s);
while (matcher.find()) {
int from = start + matcher.start();
int to = start + matcher.end();
String emot = editable.subSequence(from, to).toString();
Drawable d = getEmotDrawable(context, emot, SMALL_SCALE);
if (d != null) {
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
示例3: getInputAitSpan
public static ImageSpan getInputAitSpan(String name, float textsize) {
if (TextUtils.isEmpty(name)) {
return null;
}
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setAntiAlias(true);
paint.setTextSize(textsize);
Rect rect = new Rect();
paint.getTextBounds(name, 0, name.length(), rect);
// 获取字符串在屏幕上的长度
int width = (int) (paint.measureText(name));
final Bitmap bmp = Bitmap.createBitmap(width, rect.height(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawText(name, rect.left, rect.height() - rect.bottom, paint);
return new ImageSpan(NimUIKit.getContext(), bmp, ImageSpan.ALIGN_BOTTOM);
}
示例4: initSpanData
/**
* 重写父类的initSpanData方法
* 通过number数组得到每块数值对应的自定义MikyouBackgroundSpan对象
* 然后通过MikyouBackgroundSpan对象定义每块数值的样式包括背景,边框,边框圆角样式,然后将这些对象加入到集合中去
* 通过nonNumber数组得到每个间隔的ForegroundColorSpan对象
* 然后通过这些对象就可以定义每个间隔块的样式,因为只定义了ForegroundColorSpan所以只能定义
* 每个间隔块的字体颜色,setmGapSpanColor方式也是供外部自由定制每个间隔的样式
* 实际上还可以定义其他的Span,同理实现也是很简单的。
* */
@Override
public void initSpanData(String timeStr) {
super.initSpanData(timeStr);
vipNumbers = TimerUtils.getNumInTimerStr(timeStr);//得到每个数字注意不是每块数值,并加入数组
vipNonNumbers = TimerUtils.getNonNumInTimerStr(timeStr);//得到每个间隔字符,并加入到数组
for (int i=0;i<vipNumbers.length;i++){
for (int j=0;j<vipNumbers[i].toCharArray().length;j++){//因为需要得到每个数字所以还得遍历每块数值中的每个数字,所以需要二层循环
MikyouBackgroundSpan mSpan = new MikyouBackgroundSpan(mContext.getDrawable(mDrawableId), ImageSpan.ALIGN_BOTTOM);
initBackSpanStyle(mSpan);
mSpanList.add(mSpan);
}
}
for (int i= 0; i<vipNonNumbers.length;i++){
ForegroundColorSpan mGapSpan = new ForegroundColorSpan(mGapSpanColor);
mTextColorSpanList.add(mGapSpan);
}
}
示例5: emojify
public SpannableString emojify(SpannableString text, double size, PageLoadedListener pageLoadedListener) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) return text;
Matcher matches = EMOJI_RANGE.matcher(text);
while (matches.find()) {
String resource = Integer.toHexString(matches.group().codePointAt(0));
Drawable drawable = getEmojiDrawable(resource, size, pageLoadedListener);
if (drawable != null) {
ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
text.setSpan(imageSpan, matches.start(), matches.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return text;
}
示例6: replaceEmoticons
public static void replaceEmoticons(Context context, Editable editable, int start, int count) {
if (count <= 0 || editable.length() < start + count)
return;
CharSequence s = editable.subSequence(start, start + count);
Matcher matcher = EmoUtil.getPattern().matcher(s);
while (matcher.find()) {
int from = start + matcher.start();
int to = start + matcher.end();
String emot = editable.subSequence(from, to).toString();
Drawable d = getEmotDrawable(context, emot, DEF_SCALE);
if (d != null) {
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
示例7: displayEmoji
public static Spannable displayEmoji(Resources res, Spannable spannable, int size) {
String str = spannable.toString();
if (!str.contains(":") && !str.contains("[")) {
return spannable;
}
if (size == 0)
size = (int) TDevice.spToPx(res, 20);
Pattern pattern = Pattern.compile("(\\[[^\\[\\]:\\s\\n]+\\])|(:[^:\\[\\]\\s\\n]+:)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
String emojiStr = matcher.group();
if (TextUtils.isEmpty(emojiStr)) continue;
int resId = getEmojiResId(emojiStr);
if (resId <= 0) continue;
Drawable drawable = res.getDrawable(resId);
if (drawable == null) continue;
drawable.setBounds(0, 0, size, size);
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
spannable.setSpan(span, matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannable;
}
示例8: test01
private void test01() {
String text = "高兴[高兴] 富文本显示";
SpannableString ss = new SpannableString(text);
// 指定了一张图片
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
bitmap = Global.createBitmap(bitmap, Global.dp2px(20)); // 图片的宽高为20dp
ImageSpan span = new ImageSpan(this, bitmap, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(span, 2, 6, 0);
tv01.setText(ss); // 显示图文混排(文本中包含表情)
}
示例9: getSpannableIcon
private SpannableString getSpannableIcon(int icon, String replacement) {
SpannableString spannableIcon;
try {
Drawable image = ContextCompat.getDrawable(getApplicationContext(), icon);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
spannableIcon = new SpannableString(replacement);
spannableIcon.setSpan(imageSpan, 0, replacement.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} catch (Resources.NotFoundException e) {
spannableIcon = new SpannableString(replacement);
}
return spannableIcon;
}
示例10: getImageSpan
private static ImageSpan getImageSpan(Drawable d,int alignType) {
switch (alignType){
case ALIGN_TYPE_BOTTOM :
return new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
case ALIGN_TYPE_BASELINE :
return new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
case ALIGN_TYPE_CENTER :
default:
return new CenterImageSpan(d);
}
}
示例11: getImageSpanAlignment
private int getImageSpanAlignment() {
switch (mImageSpanAlignment) {
case IMAGE_SPAN_ALIGNMENT_BASELINE:
return ImageSpan.ALIGN_BASELINE;
case IMAGE_SPAN_ALIGNMENT_BOTTOM:
return ImageSpan.ALIGN_BOTTOM;
default:
return ImageSpan.ALIGN_BOTTOM;
}
}
示例12: initSpanData
/**
* 重写父类的initSpanData方法
* 通过number数组得到每块数值对应的自定义MikyouBackgroundSpan对象
* 然后通过MikyouBackgroundSpan对象定义每块数值的样式包括背景,边框,边框圆角样式,然后将这些对象加入到集合中去
* 通过nonNumber数组得到每个间隔的ForegroundColorSpan对象
* 然后通过这些对象就可以定义每个间隔块的样式,因为只定义了ForegroundColorSpan所以只能定义
* 每个间隔块的字体颜色,setmGapSpanColor方式也是供外部自由定制每个间隔的样式
* 实际上还可以定义其他的Span,同理实现也是很简单的。
* */
@Override
public void initSpanData(String timeStr) {
super.initSpanData(timeStr);
for (int i = 0; i<numbers.length;i++){
MikyouBackgroundSpan mBackSpan = new MikyouBackgroundSpan(mContext.getDrawable(mDrawableId), ImageSpan.ALIGN_BOTTOM);
initBackSpanStyle(mBackSpan);
mBackSpanList.add(mBackSpan);
}
for (int i= 0; i<nonNumbers.length;i++){
ForegroundColorSpan mGapSpan = new ForegroundColorSpan(mGapSpanColor);
mTextColorSpanList.add(mGapSpan);
}
}
示例13: getPageTitle
@Override
public CharSequence getPageTitle(int position) {
Drawable image = context.getResources().getDrawable(imageResId[position]);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
SpannableString sb = new SpannableString(" ");
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}
示例14: addEmotions
/**
* 将表情资源添加到文本编辑框中
*
* @param res 系统资源对象
* @param mContentEdit
* 文本编辑框
* @param emotions
* 表情资源对象
*/
public static void addEmotions(final Resources res, EditText mContentEdit, final Resource emotions) {
String newText = emotions.getResourceStr();
SpannableString ss = new SpannableString(newText);
BitmapDrawable drawable = new BitmapDrawable(res, YIResourceUtils.getResourceBitmap(emotions.getRes_id(),
EB_RESOURCE_TYPE.EB_RESOURCE_EMOTION.ordinal()));
drawable.setBounds(0, 0, 35, 35);// 设置表情图片的显示大小
ImageSpan dspan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
ss.setSpan(dspan, 0, newText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContentEdit.getText().insert(mContentEdit.getSelectionStart(), ss);
}
示例15: getPageTitle
@Override
public CharSequence getPageTitle(int position) {
image = currentContext.getResources().getDrawable(tabIcon[position]);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
// Replace blank spaces with image icon
SpannableString sb = new SpannableString(" ");
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}