Created
May 3, 2021 18:26
-
-
Save vitkidd/d9c57dc26fb28fd4ca66c5299ed334ee to your computer and use it in GitHub Desktop.
span.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void updateView(int blockPosition, boolean needPlaceHolder) { | |
Block block = blocks.get(blockPosition); | |
String imageUrl = block.getView() == null ? null : block.getView().getImageUrl(); | |
String title = block.getView() == null ? null : (block.getView().getTitle()); | |
String description = block.getView() == null ? null : block.getView().getDescription(); | |
String padding = "\n\n"; | |
if (title == null) { | |
title = ""; | |
} | |
if (description == null) { | |
description = ""; | |
} | |
int titleL = title.length(); | |
int paddingL = padding.length(); | |
int descriptionL = description.length(); | |
// Create a new spannable with the two strings | |
Spannable spannable = new SpannableString(title+padding+description); | |
// Set the custom typeface and font size to span over a section of the spannable object | |
spannable.setSpan(new CustomTypefaceSpan("", mediumTypeface), 0, titleL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
spannable.setSpan(new AbsoluteSizeSpan(sp24), 0, titleL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
spannable.setSpan(new CustomTypefaceSpan("", regularTypeface), titleL, titleL + paddingL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
spannable.setSpan(new AbsoluteSizeSpan(sp12), titleL, titleL + paddingL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
spannable.setSpan(new CustomTypefaceSpan("", regularTypeface), titleL + paddingL, titleL + paddingL + descriptionL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
spannable.setSpan(new AbsoluteSizeSpan(sp16), titleL + paddingL, titleL + paddingL + descriptionL, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
textTv.setText(spannable); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment