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 .annotation .Nullable ;
12
16
import android .support .v4 .content .ContextCompat ;
17
+ import android .text .Layout ;
13
18
import android .text .SpannableStringBuilder ;
14
19
import android .text .TextPaint ;
15
20
import android .text .method .LinkMovementMethod ;
@@ -56,7 +61,7 @@ public class SpanActivity extends BaseBackActivity {
56
61
57
62
float density ;
58
63
TextView tvAboutSpan ;
59
- TextView tvAboutAnimRainbow ;
64
+ TextView tvAboutAnimSpan ;
60
65
61
66
public static void start (Context context ) {
62
67
Intent starter = new Intent (context , SpanActivity .class );
@@ -91,7 +96,7 @@ public void updateDrawState(TextPaint ds) {
91
96
};
92
97
93
98
tvAboutSpan = findViewById (R .id .tv_about_span );
94
- tvAboutAnimRainbow = findViewById (R .id .tv_about_anim_span );
99
+ tvAboutAnimSpan = findViewById (R .id .tv_about_anim_span );
95
100
96
101
// 响应点击事件的话必须设置以下属性
97
102
tvAboutSpan .setMovementMethod (LinkMovementMethod .getInstance ());
@@ -101,58 +106,11 @@ public void updateDrawState(TextPaint ds) {
101
106
textSize = tvAboutSpan .getTextSize ();
102
107
density = getResources ().getDisplayMetrics ().density ;
103
108
104
- // initAnimSpan();
105
- // startAnim();
109
+ initAnimSpan ();
110
+ startAnim ();
106
111
107
112
108
113
tvAboutSpan .setText (new SpanUtils ()
109
- // .appendLine("SpanUtils").setBackgroundColor(Color.LTGRAY).setBold().setForegroundColor(Color.YELLOW).setAlign(Layout.Alignment.ALIGN_CENTER)
110
- // .appendLine("前景色").setForegroundColor(Color.GREEN)
111
- // .appendLine("背景色").setBackgroundColor(Color.LTGRAY)
112
- // .appendLine("行高顶部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_TOP).setBackgroundColor(Color.GREEN)
113
- // .appendLine("行高居中对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_CENTER).setBackgroundColor(Color.LTGRAY)
114
- // .appendLine("行高底部对齐").setLineHeight(2 * lineHeight, SpanUtils.ALIGN_BOTTOM).setBackgroundColor(Color.GREEN)
115
- // .appendLine("测试段落缩,首行缩进两字,其他行不缩进").setLeadingMargin((int) textSize * 2, 10).setBackgroundColor(Color.GREEN)
116
- // .appendLine("测试引用,后面的字是为了凑到两行的效果").setQuoteColor(Color.GREEN, 10, 10).setBackgroundColor(Color.LTGRAY)
117
- // .appendLine("测试列表项,后面的字是为了凑到两行的效果").setBullet(Color.GREEN, 20, 10).setBackgroundColor(Color.LTGRAY).setBackgroundColor(Color.GREEN)
118
- // .appendLine("32dp 字体").setFontSize(32, true)
119
- // .appendLine("2 倍字体").setFontProportion(2)
120
- // .appendLine("横向 2 倍字体").setFontXProportion(1.5f)
121
- // .appendLine("删除线").setStrikethrough()
122
- // .appendLine("下划线").setUnderline()
123
- // .append("测试").appendLine("上标").setSuperscript()
124
- // .append("测试").appendLine("下标").setSubscript()
125
- // .appendLine("粗体").setBold()
126
- // .appendLine("斜体").setItalic()
127
- // .appendLine("粗斜体").setBoldItalic()
128
- // .appendLine("monospace 字体").setFontFamily("monospace")
129
- // .appendLine("自定义字体").setTypeface(Typeface.createFromAsset(getAssets(), "fonts/dnmbhs.ttf"))
130
- // .appendLine("相反对齐").setAlign(Layout.Alignment.ALIGN_OPPOSITE)
131
- // .appendLine("居中对齐").setAlign(Layout.Alignment.ALIGN_CENTER)
132
- // .appendLine("正常对齐").setAlign(Layout.Alignment.ALIGN_NORMAL)
133
- // .append("测试").appendLine("点击事件").setClickSpan(clickableSpan)
134
- // .append("测试").appendLine("Url").setUrl("https://github.com/Blankj/AndroidUtilCode")
135
- // .append("测试").appendLine("模糊").setBlur(3, BlurMaskFilter.Blur.NORMAL)
136
- // .appendLine("颜色渐变").setShader(new LinearGradient(0, 0,
137
- // 64 * density * 4, 0,
138
- // getResources().getIntArray(R.array.rainbow),
139
- // null,
140
- // Shader.TileMode.REPEAT)).setFontSize(64, true)
141
- // .appendLine("图片着色").setFontSize(64, true).setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.span_cheetah),
142
- // Shader.TileMode.REPEAT,
143
- // Shader.TileMode.REPEAT))
144
- // .appendLine("阴影效果").setFontSize(64, true).setBackgroundColor(Color.BLACK).setShadow(24, 8, 8, Color.WHITE)
145
- //
146
- // .append("小图").setBackgroundColor(Color.GREEN)
147
- // .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_TOP)
148
- // .append("顶部").setBackgroundColor(Color.GREEN)
149
- // .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_CENTER)
150
- // .append("居中").setBackgroundColor(Color.GREEN)
151
- // .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BASELINE)
152
- // .append("底部").setBackgroundColor(Color.GREEN)
153
- // .appendImage(R.drawable.shape_spannable_block_low, SpanUtils.ALIGN_BOTTOM)
154
- // .appendLine("对齐").setBackgroundColor(Color.GREEN)
155
-
156
114
.appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_TOP )
157
115
.append ("大图" ).setBackgroundColor (Color .LTGRAY )
158
116
.appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_TOP )
@@ -174,6 +132,53 @@ public void updateDrawState(TextPaint ds) {
174
132
.appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_BOTTOM )
175
133
.appendLine ("对齐" ).setBackgroundColor (Color .LTGRAY )
176
134
135
+ .appendLine ("SpanUtils" ).setBackgroundColor (Color .LTGRAY ).setBold ().setForegroundColor (Color .YELLOW ).setAlign (Layout .Alignment .ALIGN_CENTER )
136
+ .appendLine ("前景色" ).setForegroundColor (Color .GREEN )
137
+ .appendLine ("背景色" ).setBackgroundColor (Color .LTGRAY )
138
+ .appendLine ("行高顶部对齐" ).setLineHeight (2 * lineHeight , SpanUtils .ALIGN_TOP ).setBackgroundColor (Color .GREEN )
139
+ .appendLine ("行高居中对齐" ).setLineHeight (2 * lineHeight , SpanUtils .ALIGN_CENTER ).setBackgroundColor (Color .LTGRAY )
140
+ .appendLine ("行高底部对齐" ).setLineHeight (2 * lineHeight , SpanUtils .ALIGN_BOTTOM ).setBackgroundColor (Color .GREEN )
141
+ .appendLine ("测试段落缩,首行缩进两字,其他行不缩进" ).setLeadingMargin ((int ) textSize * 2 , 10 ).setBackgroundColor (Color .GREEN )
142
+ .appendLine ("测试引用,后面的字是为了凑到两行的效果" ).setQuoteColor (Color .GREEN , 10 , 10 ).setBackgroundColor (Color .LTGRAY )
143
+ .appendLine ("测试列表项,后面的字是为了凑到两行的效果" ).setBullet (Color .GREEN , 20 , 10 ).setBackgroundColor (Color .LTGRAY ).setBackgroundColor (Color .GREEN )
144
+ .appendLine ("32dp 字体" ).setFontSize (32 , true )
145
+ .appendLine ("2 倍字体" ).setFontProportion (2 )
146
+ .appendLine ("横向 2 倍字体" ).setFontXProportion (1.5f )
147
+ .appendLine ("删除线" ).setStrikethrough ()
148
+ .appendLine ("下划线" ).setUnderline ()
149
+ .append ("测试" ).appendLine ("上标" ).setSuperscript ()
150
+ .append ("测试" ).appendLine ("下标" ).setSubscript ()
151
+ .appendLine ("粗体" ).setBold ()
152
+ .appendLine ("斜体" ).setItalic ()
153
+ .appendLine ("粗斜体" ).setBoldItalic ()
154
+ .appendLine ("monospace 字体" ).setFontFamily ("monospace" )
155
+ .appendLine ("自定义字体" ).setTypeface (Typeface .createFromAsset (getAssets (), "fonts/dnmbhs.ttf" ))
156
+ .appendLine ("相反对齐" ).setAlign (Layout .Alignment .ALIGN_OPPOSITE )
157
+ .appendLine ("居中对齐" ).setAlign (Layout .Alignment .ALIGN_CENTER )
158
+ .appendLine ("正常对齐" ).setAlign (Layout .Alignment .ALIGN_NORMAL )
159
+ .append ("测试" ).appendLine ("点击事件" ).setClickSpan (clickableSpan )
160
+ .append ("测试" ).appendLine ("Url" ).setUrl ("https://github.com/Blankj/AndroidUtilCode" )
161
+ .append ("测试" ).appendLine ("模糊" ).setBlur (3 , BlurMaskFilter .Blur .NORMAL )
162
+ .appendLine ("颜色渐变" ).setShader (new LinearGradient (0 , 0 ,
163
+ 64 * density * 4 , 0 ,
164
+ getResources ().getIntArray (R .array .rainbow ),
165
+ null ,
166
+ Shader .TileMode .REPEAT )).setFontSize (64 , true )
167
+ .appendLine ("图片着色" ).setFontSize (64 , true ).setShader (new BitmapShader (BitmapFactory .decodeResource (getResources (), R .drawable .span_cheetah ),
168
+ Shader .TileMode .REPEAT ,
169
+ Shader .TileMode .REPEAT ))
170
+ .appendLine ("阴影效果" ).setFontSize (64 , true ).setBackgroundColor (Color .BLACK ).setShadow (24 , 8 , 8 , Color .WHITE )
171
+
172
+ .append ("小图" ).setBackgroundColor (Color .GREEN )
173
+ .appendImage (R .drawable .shape_spannable_block_low , SpanUtils .ALIGN_TOP )
174
+ .append ("顶部" ).setBackgroundColor (Color .GREEN )
175
+ .appendImage (R .drawable .shape_spannable_block_low , SpanUtils .ALIGN_CENTER )
176
+ .append ("居中" ).setBackgroundColor (Color .GREEN )
177
+ .appendImage (R .drawable .shape_spannable_block_low , SpanUtils .ALIGN_BASELINE )
178
+ .append ("底部" ).setBackgroundColor (Color .GREEN )
179
+ .appendImage (R .drawable .shape_spannable_block_low , SpanUtils .ALIGN_BOTTOM )
180
+ .appendLine ("对齐" ).setBackgroundColor (Color .GREEN )
181
+
177
182
.append ("测试空格" ).appendSpace (30 , Color .LTGRAY ).appendSpace (50 , Color .GREEN ).appendSpace (100 ).appendSpace (30 , Color .LTGRAY ).appendSpace (50 , Color .GREEN )
178
183
.create ());
179
184
}
@@ -234,7 +239,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
234
239
mForegroundAlphaColorSpanGroup .setAlpha ((Float ) animation .getAnimatedValue ());
235
240
236
241
// update
237
- tvAboutAnimRainbow .setText (animSsb );
242
+ tvAboutAnimSpan .setText (animSsb );
238
243
}
239
244
});
240
245
0 commit comments