當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageSpan.ALIGN_BOTTOM屬性代碼示例

本文整理匯總了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);
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:26,代碼來源:EmojiUtil.java

示例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);
		}
	}
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:17,代碼來源:MoonUtil.java

示例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);
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:23,代碼來源:AitHelper.java

示例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);
    }
}
 
開發者ID:Alex-Jerry,項目名稱:LLApp,代碼行數:26,代碼來源:VIPCountDownTimer.java

示例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;
}
 
開發者ID:redcracker,項目名稱:TextSecure,代碼行數:18,代碼來源:Emoji.java

示例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);
        }
    }
}
 
開發者ID:zzwwws,項目名稱:RxZhihuDaily,代碼行數:17,代碼來源:MoonUtil.java

示例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;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:27,代碼來源:InputHelper.java

示例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);       // 顯示圖文混排(文本中包含表情)
}
 
開發者ID:JackChan1999,項目名稱:WeChatDemo,代碼行數:12,代碼來源:TextViewActivity.java

示例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;
}
 
開發者ID:pvarry,項目名稱:intra42,代碼行數:14,代碼來源:SubnotionListActivity.java

示例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);
    }
}
 
開發者ID:LightSun,項目名稱:android-common-util-light,代碼行數:11,代碼來源:StyledText.java

示例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;
    }
}
 
開發者ID:jianliaoim,項目名稱:talk-android,代碼行數:10,代碼來源:RecipientEditTextView.java

示例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);
     }
 }
 
開發者ID:Alex-Jerry,項目名稱:LLApp,代碼行數:22,代碼來源:JDCountDownTimer.java

示例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;
}
 
開發者ID:1641835946,項目名稱:MyTimeLogger,代碼行數:9,代碼來源:MyFragmentPagerAdapter.java

示例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);
}
 
開發者ID:entboost,項目名稱:EntboostIM,代碼行數:19,代碼來源:UIUtils.java

示例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;
}
 
開發者ID:Ksj7,項目名稱:BandWith,代碼行數:11,代碼來源:MainActivity.java


注:本文中的android.text.style.ImageSpan.ALIGN_BOTTOM屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。