RelativeSizeSpan

相对尺寸大小的样式。

RelativeSizeSpan(int proportion):比例。

RelativeSizeSpan(Parcel src):参数src,包含有proportion值的包装类。

示例1:

RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(18);

String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(relativeSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);

示例2:

Parcel parcel = Parcel.obtain();
parcel.writeFloat(2.5f);
parcel.setDataPosition(0);
RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(parcel);

String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(relativeSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);

示例3:

重写updateDrawState(TextPaint textPaint)方法,修改删除线的样式、文本颜色:

RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(18) {
    @Override
    public void updateDrawState(TextPaint textPaint) {
        super.updateDrawState(textPaint);
        textPaint.setColor(Color.argb(255, 54, 92, 124));
    }
};

String text = "打开百度";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(relativeSizeSpan, 2, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(spannableString);