|
3 | 3 | import android.animation.ValueAnimator; |
4 | 4 | import android.content.Context; |
5 | 5 | import android.content.Intent; |
| 6 | +import android.graphics.BitmapFactory; |
| 7 | +import android.graphics.BitmapShader; |
| 8 | +import android.graphics.BlurMaskFilter; |
6 | 9 | import android.graphics.Color; |
7 | 10 | import android.graphics.LinearGradient; |
8 | 11 | import android.graphics.Matrix; |
9 | 12 | import android.graphics.Shader; |
| 13 | +import android.graphics.Typeface; |
10 | 14 | import android.os.Bundle; |
11 | 15 | import android.support.v4.content.ContextCompat; |
| 16 | +import android.text.Layout; |
12 | 17 | import android.text.SpannableStringBuilder; |
13 | 18 | import android.text.TextPaint; |
14 | 19 | import android.text.method.LinkMovementMethod; |
@@ -101,90 +106,89 @@ public void updateDrawState(TextPaint ds) { |
101 | 106 | textSize = tvAboutSpan.getTextSize(); |
102 | 107 | density = getResources().getDisplayMetrics().density; |
103 | 108 |
|
104 | | - tvAboutSpan.setText(new SpanUtils() |
105 | | - .appendLine("测试图标文字顶部对齐测试图标文字顶部对齐测试图标文字顶部对齐测试图标文字顶部对齐").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
106 | | -// .appendLine("测试图标文字居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.GREEN) |
107 | | -// .appendLine("测试图标文字底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.LTGRAY) |
108 | | -// .appendLine("测试图标顶部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
109 | | -// .appendLine("测试图标居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
110 | | -// .appendLine("测试图标底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
111 | | -// .append("测试大图字体顶部对齐").setBackgroundColor(Color.GREEN) |
112 | | -// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
113 | | -// .appendLine() |
114 | | - .create()); |
115 | | - |
116 | | - |
117 | 109 | // tvAboutSpan.setText(new SpanUtils() |
118 | | -// .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER) |
119 | | -// .appendLine("前景色").setForegroundColor(Color.GREEN) |
120 | | -// .appendLine("背景色").setBackgroundColor(Color.LTGRAY) |
121 | | -// .appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
122 | | -// .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
123 | | -// .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
124 | | -// .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN) |
125 | | -// .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY) |
126 | | -// .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN) |
127 | | -// .appendLine("测试图标文字顶部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.LTGRAY) |
| 110 | +// .appendLine("测试图标文字顶部对齐测试图标文字顶部对齐测试图标文字顶部对齐测试图标文字顶部对齐").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
128 | 111 | // .appendLine("测试图标文字居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.GREEN) |
129 | 112 | // .appendLine("测试图标文字底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.LTGRAY) |
130 | 113 | // .appendLine("测试图标顶部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
131 | 114 | // .appendLine("测试图标居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
132 | 115 | // .appendLine("测试图标底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
133 | | -// .appendLine("32dp 字体").setFontSize(32, true) |
134 | | -// .appendLine("2 倍字体").setFontProportion(2) |
135 | | -// .appendLine("横向 2 倍字体").setFontXProportion(1.5f) |
136 | | -// .appendLine("删除线").setStrikethrough() |
137 | | -// .appendLine("下划线").setUnderline() |
138 | | -// .append("测试").appendLine("上标").setSuperscript() |
139 | | -// .append("测试").appendLine("下标").setSubscript() |
140 | | -// .appendLine("粗体").setBold() |
141 | | -// .appendLine("斜体").setItalic() |
142 | | -// .appendLine("粗斜体").setBoldItalic() |
143 | | -// .appendLine("monospace 字体").setFontFamily("monospace") |
144 | | -// .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf")) |
145 | | -// .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE) |
146 | | -// .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER) |
147 | | -// .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL) |
148 | | -// .append("测试").appendLine("点击事件").setClickSpan(clickableSpan) |
149 | | -// .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode") |
150 | | -// .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL) |
151 | | -// .appendLine("颜色渐变").setShader(new LinearGradient(0, 0, |
152 | | -// 64 * density * 4, 0, |
153 | | -// getResources().getIntArray(R.array.rainbow), |
154 | | -// null, |
155 | | -// Shader.TileMode.REPEAT)).setFontSize(64, true) |
156 | | -// .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.cheetah), |
157 | | -// Shader.TileMode.REPEAT, |
158 | | -// Shader.TileMode.REPEAT)) |
159 | | -// .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE) |
160 | | -// |
161 | | -// .append("测试小图对齐").setBackgroundColor(Color.LTGRAY) |
162 | | -// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP) |
163 | | -// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER) |
164 | | -// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE) |
165 | | -// .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM) |
166 | | -// .appendLine("end").setBackgroundColor(Color.LTGRAY) |
167 | | -// |
168 | 116 | // .append("测试大图字体顶部对齐").setBackgroundColor(Color.GREEN) |
169 | 117 | // .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
170 | | -// .append("测试大图字体顶部对齐").setBackgroundColor(Color.GREEN) |
171 | | -// .appendLine() |
172 | | -// |
173 | | -// .append("测试大图字体居中对齐").setBackgroundColor(Color.LTGRAY) |
174 | | -// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
175 | | -// .append("测试大图字体居中对齐").setBackgroundColor(Color.LTGRAY) |
176 | | -// .appendLine() |
177 | | -// |
178 | | -// .append("测试大图字体底部对齐").setBackgroundColor(Color.GREEN) |
179 | | -// .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
180 | | -// .append("测试大图字体底部对齐").setBackgroundColor(Color.GREEN) |
181 | 118 | // .appendLine() |
182 | | -// |
183 | | -// .append("测试空格").appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN).appendSpace(100).appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN) |
184 | 119 | // .create()); |
185 | | -// |
186 | | -// initAnimSpan(); |
187 | | -// startAnim(); |
| 120 | + |
| 121 | + initAnimSpan(); |
| 122 | + startAnim(); |
| 123 | + |
| 124 | + tvAboutSpan.setText(new SpanUtils() |
| 125 | + .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER) |
| 126 | + .appendLine("前景色").setForegroundColor(Color.GREEN) |
| 127 | + .appendLine("背景色").setBackgroundColor(Color.LTGRAY) |
| 128 | + .appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
| 129 | + .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
| 130 | + .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
| 131 | + .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN) |
| 132 | + .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY) |
| 133 | + .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN) |
| 134 | + .appendLine("测试图标文字顶部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.LTGRAY) |
| 135 | + .appendLine("测试图标文字居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.GREEN) |
| 136 | + .appendLine("测试图标文字底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_high, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.LTGRAY) |
| 137 | + .appendLine("测试图标顶部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN) |
| 138 | + .appendLine("测试图标居中对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY) |
| 139 | + .appendLine("测试图标底部对齐,后面的字是为了凑到两行的效果").setIconMargin(R.drawable.shape_spannable_block_low, 20, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN) |
| 140 | + .appendLine("32dp 字体").setFontSize(32, true) |
| 141 | + .appendLine("2 倍字体").setFontProportion(2) |
| 142 | + .appendLine("横向 2 倍字体").setFontXProportion(1.5f) |
| 143 | + .appendLine("删除线").setStrikethrough() |
| 144 | + .appendLine("下划线").setUnderline() |
| 145 | + .append("测试").appendLine("上标").setSuperscript() |
| 146 | + .append("测试").appendLine("下标").setSubscript() |
| 147 | + .appendLine("粗体").setBold() |
| 148 | + .appendLine("斜体").setItalic() |
| 149 | + .appendLine("粗斜体").setBoldItalic() |
| 150 | + .appendLine("monospace 字体").setFontFamily("monospace") |
| 151 | + .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf")) |
| 152 | + .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE) |
| 153 | + .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER) |
| 154 | + .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL) |
| 155 | + .append("测试").appendLine("点击事件").setClickSpan(clickableSpan) |
| 156 | + .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode") |
| 157 | + .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL) |
| 158 | + .appendLine("颜色渐变").setShader(new LinearGradient(0, 0, |
| 159 | + 64 * density * 4, 0, |
| 160 | + getResources().getIntArray(R.array.rainbow), |
| 161 | + null, |
| 162 | + Shader.TileMode.REPEAT)).setFontSize(64, true) |
| 163 | + .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.cheetah), |
| 164 | + Shader.TileMode.REPEAT, |
| 165 | + Shader.TileMode.REPEAT)) |
| 166 | + .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE) |
| 167 | + |
| 168 | + .append("测试小图对齐").setBackgroundColor(Color.LTGRAY) |
| 169 | + .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP) |
| 170 | + .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER) |
| 171 | + .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE) |
| 172 | + .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM) |
| 173 | + .appendLine("end").setBackgroundColor(Color.LTGRAY) |
| 174 | + |
| 175 | + .append("测试大图字体顶部对齐").setBackgroundColor(Color.GREEN) |
| 176 | + .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_TOP) |
| 177 | + .append("测试大图字体顶部对齐").setBackgroundColor(Color.GREEN) |
| 178 | + .appendLine() |
| 179 | + |
| 180 | + .append("测试大图字体居中对齐").setBackgroundColor(Color.LTGRAY) |
| 181 | + .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_CENTER) |
| 182 | + .append("测试大图字体居中对齐").setBackgroundColor(Color.LTGRAY) |
| 183 | + .appendLine() |
| 184 | + |
| 185 | + .append("测试大图字体底部对齐").setBackgroundColor(Color.GREEN) |
| 186 | + .appendImage(R.drawable.shape_spannable_block_high, SpanUtils.ALIGN_BOTTOM) |
| 187 | + .append("测试大图字体底部对齐").setBackgroundColor(Color.GREEN) |
| 188 | + .appendLine() |
| 189 | + |
| 190 | + .append("测试空格").appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN).appendSpace(100).appendSpace(30, Color.LTGRAY).appendSpace(50, Color.GREEN) |
| 191 | + .create()); |
188 | 192 | } |
189 | 193 |
|
190 | 194 | private void initAnimSpan() { |
|
0 commit comments