2023年7月14日发(作者:)
常用控件应用之文本框(TextView)特效
ew之跑马灯效果
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加上如下代码就行了 ected(true); ew之阴影效果(可在布局文件里加入如下属性进行设置也可通过程序设置) android:shadowDx——设置阴影横向坐标开始位置(相对于文本内容) android:shadowDy——设置阴影纵向坐标开始位置(相对于文本内容) android:shadowRadius——设置阴影的半径 android:shadowColor——指定文本阴影的颜色 //关键代码(完整代码稍后给出) dowLayer(2.5f, 15, -10, 0xff00ff00); 标签设置样式效果 补充: oLinkMask(_URLS);// 当文本内容中包含超链接格式的文本时,自动转换成超链接样式,点击会自动跳转到指定的网页 oLinkMask(_NUMBERS);//自动转手机号码点击它可进入系统拨号界面 oLinkMask(_ADDRESSES);//自动转邮件地址点击它可发送邮件(要提前设置好自己的电子邮件) oLinkMask(_ADDRESSES);//自动转街道地址点击它可查看位置(前提已安装了google地图) oLinkMask();//包括上面4种情况 关键代码(完整代码稍后给出): TextView tv = (TextView) findViewById(ml_effect); StringBuffer sb = new StringBuffer(); ("Html标签方式:
");
("
href='/bravestarrhu/'>");
(getString(ml_effect));
("
"); t(ml(ng()));
ementMethod(tance());// 这句很重要,使超链接起作用
ew之动画效果(rotate旋转、alpha透明度、scale缩放、translate移动)
实现动画需要在res/anim目录下新建对应的xml文件(稍后给出)
关键代码(完整代码稍后给出):
TextView tv = null;
// TextView旋转 动画效果
tv = (TextView) findViewById();
Animation mAnimationRight = imation(
, );
mation(mAnimationRight);
// TextView透明度动画效果
tv = (TextView) findViewById();
mAnimationRight = imation(
, );
mation(mAnimationRight);
// TextView缩放动画效果
tv = (TextView) findViewById();
mAnimationRight = imation(
, );
mation(mAnimationRight);
// TextView移动动画效果
tv = (TextView) findViewById(ate);
mAnimationRight = imation(
, ate);
mation(mAnimationRight);
ew之霓虹灯效果
采用timer+TimerTask+Handler实现
主要用到SpannableStringBuilder对象
关键代码(完整代码稍后给出):
// 霓虹灯效果(此段代码会使"光"变红色)
String wholeContent = "欢迎光临";
SpannableStringBuilder spannable = new SpannableStringBuilder(
wholeContent);
n(new ForegroundColorSpan(), 2,
3, _EXCLUSIVE_INCLUSIVE); // 设置指定位置文字的颜色(索引0开始)
ew之包含图片的效果
实现步骤(1.构建ImageGetter;2.直接使用append进行追加)
关键代码(完整代码稍后给出):
TextView tv = (TextView) findViewById(_effect);
t(_effect);
// 通过HTML标记获得res目录下指定的图片
ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int id = nt(source);
// 根据id从资源文件中获取图片对象
Drawable d = getResources().getDrawable(id);
nds(0, 0, rinsicWidth(), rinsicHeight());
return d;
}
};
(ml("",
imageGetter, null));
完整代码:
1>清单文件
package="eweffect" android:versionCode="1" android:versionName="1.0" > android:icon="@drawable/ic_launcher" android:label="@string/app_name" > android:name=".TextViewEffectActivity" android:label="@string/app_name" >
2>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > 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" /> android:id="@+id/shadow_effect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" /> 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>
4>
android:duration="500" android:fromAlpha="1.0" android:toAlpha="0.0" android:repeatCount="10"/> 5> xmlns:android="/apk/res/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" /> 6> 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" /> 7> android:fromXDelta="320" android:toXDelta="0" android:fromYDelta="480" android:toYDelta="0" android:duration="5000" android:repeatCount="10" /> 8> package eweffect; import ist; import p; import ; import ; import ; import ask; import ty; import ; import le; import ; import r; import e; import ; import etter; import vementMethod; import ion; import ionUtils; import ew; import bleStringBuilderUtils; /** * @Author BraveStarr * @QQ 1733259520 * @Blog /bravestarrhu/,/ * wanghubravestarr * */ public class TextViewEffectActivity extends Activity { private static final int[] colors = new int[] { , , , , }; private int currColor = 0;// 当前第一个文字的颜色 @Override public void onCreate(Bundle savedInstanceState) { te(savedInstanceState); setContentView(); TextView tv = null; // 跑马灯效果文本框 tv = (TextView) findViewById(e_effect); tSize(28); tColor(0xffd0eeee); ected(true);// 要实现界面上有多个跑马灯时需要加入这句 // 阴影效果 tv = (TextView) findViewById(_effect); tSize(28); tColor(0xffd0eeee); t(_effect); dowLayer(2.5f, 15, -10, 0xff00ff00); // HTML标签实现效果 tv = (TextView) findViewById(ml_effect); // 当文本内容中包含超链接格式的文本时,自动转换成超链接样式,点击会自动跳转到指定的网页,文本框还能实现自动转手机号码/邮件/地图 // _NUMBERS为自动转手机号码点击它可进入系统拨号界面 // _ADDRESSES为自动转邮件地址点击它可发送邮件(要提前设置好自己的电子邮件) // _ADDRESSES为自动转街道地址点击它可查看位置(前提已安装了google地图) // 包括WEB_URLS、EMAIL_ADDRESSES、PHONE_NUMBERS和MAP_ADDRESSES // oLinkMask(_URLS); StringBuffer sb = new StringBuffer(); (" (" href='/bravestarrhu/'>"); (getString(ml_effect)); (" t(ml(ng())); ementMethod(tance());// 这句很重要,使超链接起作用 // TextView旋转 动画效果 tv = (TextView) findViewById(); Animation mAnimationRight = imation( , ); mation(mAnimationRight); // TextView透明度动画效果 tv = (TextView) findViewById(); mAnimationRight = imation( , ); mation(mAnimationRight); // TextView缩放动画效果 tv = (TextView) findViewById(); mAnimationRight = imation( , ); mation(mAnimationRight); // TextView移动动画效果 tv = (TextView) findViewById(ate); mAnimationRight = imation( , ate); mation(mAnimationRight); // 霓虹灯效果,延时1秒转第一次,从此以后每隔1秒又开始执行执行 le(task_neon, 1000, 1000); // 包含图片的效果(1.构建ImageGetter;2.直接使用append进行追加) tv = (TextView) findViewById(_effect); t(_effect); // 通过HTML标记获得res目录下指定的图片 ImageGetter imageGetter = new ImageGetter() { @Override public Drawable getDrawable(String source) { int id = nt(source); // 根据id从资源文件中获取图片对象 Drawable d = getResources().getDrawable(id); nds(0, 0, rinsicWidth(), rinsicHeight()); return d; } }; (ml("", imageGetter, null)); } Timer timer = new Timer(); TimerTask task_neon = new TimerTask() { public void run() { Message message = new Message(); = 1; ssage(message); } }; final Handler handler = new Handler() { public void handleMessage(Message msg) { switch () { case 1: // 霓虹灯效果 TextView tv = (TextView) findViewById(ghts_effect); String neontext = getString(ghts_effect); int len = (); int colorsize = ; List
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689327968a230504.htmlHtml标签方式:
");
");
评论列表(0条)