<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="跑马灯效果,实验即如果" android:textSize="@dimen/font26" android:textColor="@color/blue1" android:layout_margin="20dp" android:singleLine="true"//实现跑马灯的条件1,即所有内容以一行显示 android:ellipsize="marquee"//字幕的效果 有start,end ,middle,marquee,none, start:表示开头省略掉,通常是...开始 常用end:表示结尾省略掉,多余的部分以...表示 middle:表示中间省略 marquee:表示跑马灯效果 android:marqueeRepeatLimit="marquee_forever"//跑马灯的效果次数,可以用正整数设定。 android:focusable="true"//如果使用跑马灯效果必须单独使用,且必须聚焦 android:focusableInTouchMode="true" /> 2============================================== 实现特定字符的特定显示,比如实现“
”这一句数值的放大,与颜色的醒目,首先在xml文档中,录入相关的语句,可以在前面加入图片,使用drawableLeft,使开头走过路过,不要错过,原价900的品牌服饰,现在只要6折,只要500块
有一张图片,<TextView android:id="@+id/textview_spanning_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/green2" android:drawableLeft="@drawable/pic" android:text="走过路过,不要错过,原价900的品牌服饰,现在只要6折,只要500块" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="10dp" android:paddingBottom="10dp" android:textColor="@color/red1"/> 然后在Avtivity的启动处 1.找到该文档mTextView=(TextView) findViewById(R.id.textview_spanning_txt); 然后把找到的内容转化为字符串String content=mTextView.getText().toString(); 使用实例化SpannableString方法,加载得到的字符串内容contentSpannableString spannableString=new SpannableString(content);spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue)), 12,15,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ForegroundColorSpan是设定想设定字体的颜色的, 12,15是12开头的字符,15结束但不包括该字符, spannableString.setSpan(new AbsoluteSizeSpan(35,true), 12, 15,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); AbsoluteSizeSpan是设定字体的大小 spannableString.setSpan(new StyleSpan(Typeface.BOLD), 12,15,Spanned.SPAN_INCLUSIVE_EXCLUSIVE); StyleSpan(Typeface,Bold)是设定字体的大小的,
实现文本录入的跑马灯效果与特定字符的特殊显示
最新推荐文章于 2021-07-23 17:24:39 发布