知识共享android TextView各种效果雷惊风.docx
- 文档编号:604568
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:24
- 大小:24.56KB
知识共享android TextView各种效果雷惊风.docx
《知识共享android TextView各种效果雷惊风.docx》由会员分享,可在线阅读,更多相关《知识共享android TextView各种效果雷惊风.docx(24页珍藏版)》请在冰点文库上搜索。
知识共享androidTextView各种效果雷惊风
常用控件应用之文本框(TextView)特效
1.TextView之跑马灯效果
android:
ellipsize属性使用之跑马灯效果
android:
ellipsize
设置当文字过长时,该控件该如何显示。
有如下值设置:
"start"—–省略号显示在开头
"end"——省略号显示在结尾
"middle"—-省略号显示在中间
"marquee"——以跑马灯的方式显示(动画横向向左移动)
布局文件中给TextView加入如下属性即可:
android:
ellipsize="marquee"
android:
marqueeRepeatLimit="marquee_forever"
android:
focusable="true"
android:
focusableInTouchMode="true"
布局文件中设置如下(完整代码稍后给出)
android: id="@+id/marquee_effect" android: layout_width="100dip" android: layout_height="wrap_content" android: layout_gravity="center_horizontal" android: ellipsize="marquee" android: focusable="true" android: focusableInTouchMode="true" android: marqueeRepeatLimit="marquee_forever" android: singleLine="true" android: text="@string/marquee_effect"/> 如果一个页面想实现多个TextView同时跑马灯效果解决方案: 给要跑动的textview加上如下代码就行了 textview.setSelected(true); 2.TextView之阴影效果(可在布局文件里加入如下属性进行设置也可通过程序设置) android: shadowDx——设置阴影横向坐标开始位置(相对于文本内容) android: shadowDy——设置阴影纵向坐标开始位置(相对于文本内容) android: shadowRadius——设置阴影的半径 android: shadowColor——指定文本阴影的颜色 //关键代码(完整代码稍后给出) textview.setShadowLayer(2.5f,15,-10,0xff00ff00); 3.html标签设置样式效果 补充: textView.setAutoLinkMask(Linkify.WEB_URLS);//当文本内容中包含超链接格式的文本时,自动转换成超链接样式,点击会自动跳转到指定的网页 textView.setAutoLinkMask(Linkify.PHONE_NUMBERS);//自动转手机号码点击它可进入系统拨号界面 textView.setAutoLinkMask(Linkify.EMAIL_ADDRESSES);//自动转邮件地址点击它可发送邮件(要提前设置好自己的电子邮件) textView.setAutoLinkMask(Linkify.MAP_ADDRESSES);//自动转街道地址点击它可查看位置(前提已安装了google地图) textView.setAutoLinkMask(Linkify.ALL);//包括上面4种情况 关键代码(完整代码稍后给出): TextViewtv=(TextView)findViewById(R.id.fromhtml_effect); StringBuffersb=newStringBuffer(); sb.append("
");
sb.append("
sb.append(getString(R.string.fromhtml_effect));
sb.append("
");sb.append(getString(R.string.fromhtml_effect));
sb.append("
tv.setText(Html.fromHtml(sb.toString()));
tv.setMovementMethod(LinkMovementMethod.getInstance());//这句很重要,使超链接
4.TextView之动画效果(rotate旋转、alpha透明度、scale缩放、translate移动)
实现动画需要在res/anim目录下新建对应的xml文件(稍后给出)
关键代码(完整代码稍后给出):
TextViewtv=null;
//TextView旋转动画效果
tv=(TextView)findViewById(R.id.rotate);
AnimationmAnimationRight=AnimationUtils.loadAnimation(
TextViewEffectActivity.this,R.anim.rotate);
tv.setAnimation(mAnimationRight);
//TextView透明度动画效果
tv=(TextView)findViewById(R.id.alpha);
mAnimationRight=AnimationUtils.loadAnimation(
TextViewEffectActivity.this,R.anim.alpha);
tv.setAnimation(mAnimationRight);
//TextView缩放动画效果
tv=(TextView)findViewById(R.id.scale);
mAnimationRight=AnimationUtils.loadAnimation(
TextViewEffectActivity.this,R.anim.scale);
tv.setAnimation(mAnimationRight);
//TextView移动动画效果
tv=(TextView)findViewById(R.id.translate);
mAnimationRight=AnimationUtils.loadAnimation(
TextViewEffectActivity.this,R.anim.translate);
tv.setAnimation(mAnimationRight);
5.TextView之霓虹灯效果
采用timer+TimerTask+Handler实现
主要用到SpannableStringBuilder对象
关键代码(完整代码稍后给出):
//霓虹灯效果(此段代码会使"光"变红色)
StringwholeContent="欢迎光临";
SpannableStringBuilderspannable=newSpannableStringBuilder(
wholeContent);
spannable.setSpan(newForegroundColorSpan(Color.RED),2,
3,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);//设置指定位置文字的颜色(索引0开始)
6.TextView之包含图片的效果
实现步骤(1.构建ImageGetter;2.直接使用append进行追加)
关键代码(完整代码稍后给出):
TextViewtv=(TextView)findViewById(R.id.image_effect);
tv.setText(R.string.image_effect);
//通过HTML标记获得res目录下指定的图片
ImageGetterimageGetter=newImageGetter(){
@Override
publicDrawablegetDrawable(Stringsource){
intid=Integer.parseInt(source);
//根据id从资源文件中获取图片对象
Drawabled=getResources().getDrawable(id);
d.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight());
returnd;
}
};
tv.append(Html.fromHtml("
imageGetter,null));
完整代码:
1>清单文件AndroidManifest.xml
xmlversion="1.0"encoding="utf-8"?
>
android=" package="com.bravestarr.app.textvieweffect" android: versionCode="1" android: versionName="1.0"> minSdkVersion="7"/> android: icon="@drawable/ic_launcher" android: label="@string/app_name"> android: name=".TextViewEffectActivity" android: label="@string/app_name"> name="android.intent.action.MAIN"/> name="android.intent.category.LAUNCHER"/> 2>main.xml xmlversion="1.0"encoding="utf-8"? > android=" android: layout_width="fill_parent" android: layout_height="fill_parent" android: orientation="vertical"> -- android: ellipsize属性使用之跑马灯效果 android: ellipsize 设置当文字过长时,该控件该如何显示。 有如下值设置: "start"—–省略号显示在开头 "end"——省略号显示在结尾 "middle"—-省略号显示在中间 "marquee"——以跑马灯的方式显示(动画横向向左移动) 关键代码: android: ellipsize="marquee" android: marqueeRepeatLimit="marquee_forever" android: focusable="true" android: focusableInTouchMode="true" 如果一个页面想实现多个TextView同时跑马灯效果解决方案: 代码中给要跑动的textview加上textview.setSelected(true);就行了 --> android: id="@+id/marquee_effect" android: layout_width="100dip" android: layout_height="wrap_content" android: layout_gravity="center_horizontal" android: ellipsize="marquee" android: focusable="true" android: focusableInTouchMode="true" android: marqueeRepeatLimit="marquee_forever" android: singleLine="true" android: text="@string/marquee_effect"/> -- TextView之阴影效果 android: shadowDx——设置阴影横向坐标开始位置(相对于文本内容) android: shadowDy——设置阴影纵向坐标开始位置(相对于文本内容) android: shadowRadius——设置阴影的半径 android: shadowColor——指定文本阴影的颜色 --> android: id="@+id/shadow_effect" android: layout_width="wrap_content" android: layout_height="wrap_content" android: singleLine="true"/> --html设置样式效果--> android: id="@+id/fromhtml_effect" android: layout_width="wrap_content" android: layout_height="wrap_content" android: singleLine="true"/> --动画效果--> android: id="@+id/alpha" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/alpha_animation_effect" /> android: id="@+id/rotate" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/rotate_animation_effect"/> android: id="@+id/scale" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/scale_animation_effect"/> android: id="@+id/translate" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/translate_animation_effect"/> --霓虹灯效果--> android: id="@+id/neonlights_effect" android: layout_width="wrap_content" android: layout_height="wrap_content"/> --包含图片的效果--> android: id="@+id/image_effect" android: layout_width="wrap_content" android: layout_height="wrap_content"/> 3>strings.xml xmlversion="1.0"encoding="utf-8"? > 4>alpha.xml xmlversion="1.0"encoding="utf-8"? > android="> android: duration="500" android: fromAlpha="1.0" android: toAlpha="0.0" android: repeatCount="10"/> -- fromAlpha: 开始时透明度 toAlpha: 结束时透明度 duration: 动画持续时间 应用: 例1: 淡出效果 android: fromAlpha="1.0" android: toAlpha="0.0" 例2: 淡入效果 android: fromAlpha="0.0" android: toAlpha="1.0" --> 5>rotate.xml xmlversion="1.0"encoding="utf-8"? > xmlns: android=" android: duration="500" android: fromDegrees="0" android: interpolator="@android: anim/linear_interpolator" android: pivotX="50%" android: pivotY="50%" android: repeatCount="10" android: toDegrees="-90"/> -- fromDegrees动画开始时的角度 toDegrees动画结束时物件的旋转角度,正代表顺时针 pivotX属性为动画相对于物件的X坐标的开始位置 pivotY属性为动画相对于物件的Y坐标的开始位置 duration: 动画持续时间 --> 6>scale.xml xmlversion="1.0"encoding="utf-8"? > android=" android: interpolator="@android: anim/decelerate_interpolator" android: fromXScale="0.0" android: toXScale="1.5" android: fromYScale="0.0" android: toYScale="1.5" android: pivotX="50%" android: pivotY="50%" android: startOffset="0" android: duration="5000" android: repeatCount="3" android: repeatMode="reverse" /> -- interpolator指定动画插入器,常见的有加速减速插入器accelerate_decelerate_interpolator,加速插入器accelerate_interpolator,减速插入器decelerate_interpolator。 fromXScale,fromYScale,动画开始前X,Y的缩放,0.0为不显示,1.0为正常大小 toXScale,toYScale,动画最终缩放的倍数,1.0为正常大小,大于1.0放大 pivotX,pivotY动画起始位置,相对于屏幕的百分比,两个都为50%表示动画从屏幕中间开始 startOffset,动画多次执行的间隔时间,如果只执行一次,执行前会暂停这段时间,单位毫秒 duration,一次动画效果消耗的时间,单位毫秒,值越小动画速度越快 repeatCount,动画重复的计数,动画将会执行该值+1次 repeatMode,动画重复的模式,reverse为反向,当第偶次执行时,动画方向会相反。 restart为重新执行,方向不变 --> 7>translate.xml xmlversion="1.0"encoding="utf-8"? > android="
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 知识共享android TextView各种效果雷惊风 知识 共享 android TextView 各种 效果 惊风
![提示](https://static.bingdoc.com/images/bang_tan.gif)