33import android .animation .ValueAnimator ;
44import android .content .Context ;
55import android .content .Intent ;
6+ import android .graphics .BitmapFactory ;
7+ import android .graphics .BitmapShader ;
8+ import android .graphics .BlurMaskFilter ;
69import android .graphics .Color ;
710import android .graphics .LinearGradient ;
811import android .graphics .Matrix ;
912import android .graphics .Shader ;
13+ import android .graphics .Typeface ;
1014import android .os .Bundle ;
1115import android .support .annotation .Nullable ;
1216import android .support .v4 .content .ContextCompat ;
17+ import android .text .Layout ;
1318import android .text .SpannableStringBuilder ;
1419import android .text .TextPaint ;
1520import android .text .method .LinkMovementMethod ;
@@ -56,7 +61,7 @@ public class SpanActivity extends BaseBackActivity {
5661
5762 float density ;
5863 TextView tvAboutSpan ;
59- TextView tvAboutAnimRainbow ;
64+ TextView tvAboutAnimSpan ;
6065
6166 public static void start (Context context ) {
6267 Intent starter = new Intent (context , SpanActivity .class );
@@ -91,7 +96,7 @@ public void updateDrawState(TextPaint ds) {
9196 };
9297
9398 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 );
95100
96101 // 响应点击事件的话必须设置以下属性
97102 tvAboutSpan .setMovementMethod (LinkMovementMethod .getInstance ());
@@ -101,58 +106,11 @@ public void updateDrawState(TextPaint ds) {
101106 textSize = tvAboutSpan .getTextSize ();
102107 density = getResources ().getDisplayMetrics ().density ;
103108
104- // initAnimSpan();
105- // startAnim();
109+ initAnimSpan ();
110+ startAnim ();
106111
107112
108113 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-
156114 .appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_TOP )
157115 .append ("大图" ).setBackgroundColor (Color .LTGRAY )
158116 .appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_TOP )
@@ -174,6 +132,53 @@ public void updateDrawState(TextPaint ds) {
174132 .appendImage (R .drawable .shape_spannable_block_high , SpanUtils .ALIGN_BOTTOM )
175133 .appendLine ("对齐" ).setBackgroundColor (Color .LTGRAY )
176134
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+
177182 .append ("测试空格" ).appendSpace (30 , Color .LTGRAY ).appendSpace (50 , Color .GREEN ).appendSpace (100 ).appendSpace (30 , Color .LTGRAY ).appendSpace (50 , Color .GREEN )
178183 .create ());
179184 }
@@ -234,7 +239,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
234239 mForegroundAlphaColorSpanGroup .setAlpha ((Float ) animation .getAnimatedValue ());
235240
236241 // update
237- tvAboutAnimRainbow .setText (animSsb );
242+ tvAboutAnimSpan .setText (animSsb );
238243 }
239244 });
240245
0 commit comments