1.TextView之跑馬燈效果
android:ellipsize屬性使用之跑馬燈效果 android:ellipsize 設(shè)置當(dāng)文字過長時,該控件該如何顯示。有如下值設(shè)置: "start"—–省略號顯示在開頭 "end"——省略號顯示在結(jié)尾 "middle"—-省略號顯示在中間 "marquee" ——以跑馬燈的方式顯示(動畫橫向向左移動) 布局文件中給TextView加入如下屬性即可: android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true"
<!-- 布局文件中設(shè)置如下(完整代碼稍后給出) --> <TextView 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" />
如果一個頁面想實現(xiàn)多個TextView同時跑馬燈效果解決方案:給要跑動的textview加上如下代碼就行了
textview.setSelected(
true
);
2.TextView之陰影效果(可在布局文件里加入如下屬性進(jìn)行設(shè)置也可通過程序設(shè)置)
android:shadowDx——設(shè)置陰影橫向坐標(biāo)開始位置(相對于文本內(nèi)容)
android:shadowDy——設(shè)置陰影縱向坐標(biāo)開始位置(相對于文本內(nèi)容)
android:shadowRadius——設(shè)置陰影的半徑
android:shadowColor——指定文本陰影的顏色
//關(guān)鍵代碼(完整代碼稍后給出) textview.setShadowLayer(2.5f, 15, -10, 0xff00ff00);
3.html標(biāo)簽設(shè)置樣式效果
補(bǔ)充:
textView.setAutoLinkMask(Linkify.WEB_URLS);// 當(dāng)文本內(nèi)容中包含超鏈接格式的文本時,自動轉(zhuǎn)換成超鏈接樣式,點擊會自動跳轉(zhuǎn)到指定的網(wǎng)頁
textView.setAutoLinkMask(Linkify.PHONE_NUMBERS);//自動轉(zhuǎn)手機(jī)號碼點擊它可進(jìn)入系統(tǒng)撥號界面
textView.setAutoLinkMask(Linkify.EMAIL_ADDRESSES);//自動轉(zhuǎn)郵件地址點擊它可發(fā)送郵件(要提前設(shè)置好自己的電子郵件)
textView.setAutoLinkMask(Linkify.MAP_ADDRESSES);//自動轉(zhuǎn)街道地址點擊它可查看位置(前提已安裝了google地圖)
textView.setAutoLinkMask(Linkify.ALL);//包括上面4種情況
關(guān)鍵代碼(完整代碼稍后給出):
TextView tv = (TextView) findViewById(R.id.fromhtml_effect); StringBuffer sb = new StringBuffer(); sb.append( "<h1><font color='#ff0000'>Html標(biāo)簽方式:</font></h1>" ); sb.append( "<h6><b><i><font color='#00ff00'><a ); sb.append(getString(R.string.fromhtml_effect)); sb.append( "</a></font></i></b></h6>" ); tv.setText(Html.fromHtml(sb.toString())); tv.setMovementMethod(LinkMovementMethod.getInstance()); // 這句很重要,使超鏈接<a href>起作用
4.TextView之動畫效果(rotate旋轉(zhuǎn)、alpha透明度、scale縮放、translate移動)
實現(xiàn)動畫需要在res/anim目錄下新建對應(yīng)的xml文件(稍后給出)
關(guān)鍵代碼(完整代碼稍后給出):
TextView tv = null ; // TextView旋轉(zhuǎn) 動畫效果 tv = (TextView) findViewById(R.id.rotate); Animation mAnimationRight = 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實現(xiàn)
主要用到SpannableStringBuilder對象
關(guān)鍵代碼(完整代碼稍后給出):
// 霓虹燈效果(此段代碼會使"光"變紅色) String wholeContent = "歡迎光臨" ; SpannableStringBuilder spannable = new SpannableStringBuilder( wholeContent); spannable.setSpan( new ForegroundColorSpan(Color.RED), 2 , 3, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 設(shè)置指定位置文字的顏色(索引0開始)
6.TextView之包含圖片的效果
實現(xiàn)步驟(1.構(gòu)建ImageGetter;2.直接使用append進(jìn)行追加)
關(guān)鍵代碼(完整代碼稍后給出):
TextView tv = (TextView) findViewById(R.id.image_effect); tv.setText(R.string.image_effect); // 通過HTML標(biāo)記獲得res目錄下指定的圖片 ImageGetter imageGetter = new ImageGetter() { @Override public Drawable getDrawable(String source) { int id = Integer.parseInt(source); // 根據(jù)id從資源文件中獲取圖片對象 Drawable d = getResources().getDrawable(id); d.setBounds( 0, 0 , d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; tv.append(Html.fromHtml( "<img src='" + R.drawable.log + "'/>" , imageGetter, null ));
上圖:
目錄結(jié)構(gòu)如下:
完整代碼:
1>清單文件AndroidManifest.xml
<? xml version="1.0" encoding="utf-8" ?> < manifest xmlns:android ="http://schemas.android.com/apk/res/android" package ="com.bravestarr.app.textvieweffect" android:versionCode ="1" android:versionName ="1.0" > < uses-sdk android:minSdkVersion ="7" /> < application android:icon ="@drawable/ic_launcher" android:label ="@string/app_name" > < activity android:name =".TextViewEffectActivity" android:label ="@string/app_name" > < intent-filter > < action android:name ="android.intent.action.MAIN" /> < category android:name ="android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > </ application > </ manifest >
2>main.xml
<? xml version="1.0" encoding="utf-8" ?> < LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:layout_width ="fill_parent" android:layout_height ="fill_parent" android:orientation ="vertical" > <!-- android:ellipsize屬性使用之跑馬燈效果 android:ellipsize 設(shè)置當(dāng)文字過長時,該控件該如何顯示。有如下值設(shè)置: "start"—–省略號顯示在開頭 "end"——省略號顯示在結(jié)尾 "middle"—-省略號顯示在中間 "marquee" ——以跑馬燈的方式顯示(動畫橫向向左移動) 關(guān)鍵代碼: android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" 如果一個頁面想實現(xiàn)多個TextView同時跑馬燈效果解決方案:代碼中給要跑動的textview加上textview.setSelected(true);就行了 --> < TextView 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——設(shè)置陰影橫向坐標(biāo)開始位置(相對于文本內(nèi)容) android:shadowDy——設(shè)置陰影縱向坐標(biāo)開始位置(相對于文本內(nèi)容) android:shadowRadius——設(shè)置陰影的半徑 android:shadowColor——指定文本陰影的顏色 --> < TextView android:id ="@+id/shadow_effect" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:singleLine ="true" /> <!-- html設(shè)置樣式效果 --> < TextView android:id ="@+id/fromhtml_effect" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:singleLine ="true" /> <!-- 動畫效果 --> < TextView android:id ="@+id/alpha" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:text ="@string/alpha_animation_effect" /> < TextView android:id ="@+id/rotate" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:text ="@string/rotate_animation_effect" /> < TextView android:id ="@+id/scale" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:text ="@string/scale_animation_effect" /> < TextView android:id ="@+id/translate" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:text ="@string/translate_animation_effect" /> <!-- 霓虹燈效果 --> < TextView android:id ="@+id/neonlights_effect" android:layout_width ="wrap_content" android:layout_height ="wrap_content" /> <!-- 包含圖片的效果 --> < TextView android:id ="@+id/image_effect" android:layout_width ="wrap_content" android:layout_height ="wrap_content" /> </ LinearLayout >
3>strings.xml
<? xml version="1.0" encoding="utf-8" ?> < resources > < string name ="app_name" > TextView效果集錦 </ string > < string name ="marquee_effect" > 跑馬燈效果 </ string > < string name ="shadow_effect" > 陰影效果 </ string > < string name ="fromhtml_effect" > fromhtml設(shè)置效果 </ string > < string name ="alpha_animation_effect" > 文本透明度動畫效果 </ string > < string name ="rotate_animation_effect" > 文本旋轉(zhuǎn)動畫效果 </ string > < string name ="scale_animation_effect" > 文本縮放動畫效果 </ string > < string name ="translate_animation_effect" > 文本移動動畫效果 </ string > < string name ="neonlights_effect" > 霓虹燈效果 </ string > < string name ="image_effect" > 包含圖片的TextView效果 </ string > </ resources >
4>alpha.xml
<? xml version="1.0" encoding="utf-8" ?> < set xmlns:android ="http://schemas.android.com/apk/res/android" > < alpha android:duration ="500" android:fromAlpha ="1.0" android:toAlpha ="0.0" android:repeatCount ="10" /> </ set > <!-- fromAlpha:開始時透明度 toAlpha: 結(jié)束時透明度 duration:動畫持續(xù)時間 應(yīng)用: 例1:淡出效果 android:fromAlpha="1.0" android:toAlpha="0.0" 例2:淡入效果 android:fromAlpha="0.0" android:toAlpha="1.0" -->
5>rotate.xml
<? xml version="1.0" encoding="utf-8" ?> < set > < rotate xmlns:android ="http://schemas.android.com/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" /> </ set > <!-- fromDegrees 動畫開始時的角度 toDegrees 動畫結(jié)束時物件的旋轉(zhuǎn)角度,正代表順時針 pivotX 屬性為動畫相對于物件的X坐標(biāo)的開始位置 pivotY 屬性為動畫相對于物件的Y坐標(biāo)的開始位置 duration:動畫持續(xù)時間 -->
6>scale.xml
<? xml version="1.0" encoding="utf-8" ?> < set xmlns:android ="http://schemas.android.com/apk/res/android" > < scale 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" /> </ set > <!-- interpolator指定動畫插入器,常見的有加速減速插入器accelerate_decelerate_interpolator,加速插入器accelerate_interpolator,減速插入器decelerate_interpolator。 fromXScale,fromYScale,動畫開始前X,Y的縮放,0.0為不顯示,1.0為正常大小 toXScale,toYScale,動畫最終縮放的倍數(shù),1.0為正常大小,大于1.0放大 pivotX,pivotY動畫起始位置,相對于屏幕的百分比,兩個都為50%表示動畫從屏幕中間開始 startOffset,動畫多次執(zhí)行的間隔時間,如果只執(zhí)行一次,執(zhí)行前會暫停這段時間,單位毫秒 duration,一次動畫效果消耗的時間,單位毫秒,值越小動畫速度越快 repeatCount,動畫重復(fù)的計數(shù),動畫將會執(zhí)行該值+1次 repeatMode,動畫重復(fù)的模式,reverse為反向,當(dāng)?shù)谂即螆?zhí)行時,動畫方向會相反。restart為重新執(zhí)行,方向不變 -->
7>translate.xml
<? xml version="1.0" encoding="utf-8" ?> < set xmlns:android ="http://schemas.android.com/apk/res/android" > < translate android:fromXDelta ="320" android:toXDelta ="0" android:fromYDelta ="480" android:toYDelta ="0" android:duration ="5000" android:repeatCount ="10" /> </ set > <!-- fromXDelta,fromYDelta起始時X,Y座標(biāo),屏幕右下角的座標(biāo)是X:320,Y:480 toXDelta,toYDelta動畫結(jié)束時X,Y的座標(biāo) -->
8>TextViewEffectActivity.java
package com.bravestarr.app.textvieweffect; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.Html; import android.text.Html.ImageGetter; import android.text.method.LinkMovementMethod; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.TextView; import com.bravestarr.app.utils.SpannableStringBuilderUtils; /** * @Author BraveStarr * @QQ 1733259520 * @Blog http://www.cnblogs.com/bravestarrhu/ , http://blog.sina.com.cn/ * wanghubravestarr * */ public class TextViewEffectActivity extends Activity { private static final int [] colors = new int [] { Color.RED, Color.GRAY, Color.GREEN, Color.LTGRAY, Color.BLUE }; private int currColor = 0; // 當(dāng)前第一個文字的顏色 @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = null ; // 跑馬燈效果文本框 tv = (TextView) findViewById(R.id.marquee_effect); tv.setTextSize( 28 ); tv.setTextColor( 0xffd0eeee ); tv.setSelected( true ); // 要實現(xiàn)界面上有多個跑馬燈時需要加入這句 // 陰影效果 tv = (TextView) findViewById(R.id.shadow_effect); tv.setTextSize( 28 ); tv.setTextColor( 0xffd0eeee ); tv.setText(R.string.shadow_effect); tv.setShadowLayer( 2.5f, 15, -10, 0xff00ff00 ); // HTML標(biāo)簽實現(xiàn)效果 tv = (TextView) findViewById(R.id.fromhtml_effect); // 當(dāng)文本內(nèi)容中包含超鏈接格式的文本時,自動轉(zhuǎn)換成超鏈接樣式,點擊會自動跳轉(zhuǎn)到指定的網(wǎng)頁,文本框還能實現(xiàn)自動轉(zhuǎn)手機(jī)號碼/郵件/地圖 // Linkify.PHONE_NUMBERS為自動轉(zhuǎn)手機(jī)號碼點擊它可進(jìn)入系統(tǒng)撥號界面 // Linkify.EMAIL_ADDRESSES為自動轉(zhuǎn)郵件地址點擊它可發(fā)送郵件(要提前設(shè)置好自己的電子郵件) // Linkify.MAP_ADDRESSES為自動轉(zhuǎn)街道地址點擊它可查看位置(前提已安裝了google地圖) // Linkify.ALL包括WEB_URLS、EMAIL_ADDRESSES、PHONE_NUMBERS和MAP_ADDRESSES // tv.setAutoLinkMask(Linkify.WEB_URLS); StringBuffer sb = new StringBuffer(); sb.append( "<h1><font color='#ff0000'>Html標(biāo)簽方式:</font></h1>" ); sb.append( "<h6><b><i><font color='#00ff00'><a ); sb.append(getString(R.string.fromhtml_effect)); sb.append( "</a></font></i></b></h6>" ); tv.setText(Html.fromHtml(sb.toString())); tv.setMovementMethod(LinkMovementMethod.getInstance()); // 這句很重要,使超鏈接<a href>起作用 // TextView旋轉(zhuǎn) 動畫效果 tv = (TextView) findViewById(R.id.rotate); Animation mAnimationRight = 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); // 霓虹燈效果,延時1秒轉(zhuǎn)第一次,從此以后每隔1秒又開始執(zhí)行執(zhí)行 timer.schedule(task_neon, 1000, 1000 ); // 包含圖片的效果(1.構(gòu)建ImageGetter;2.直接使用append進(jìn)行追加) tv = (TextView) findViewById(R.id.image_effect); tv.setText(R.string.image_effect); // 通過HTML標(biāo)記獲得res目錄下指定的圖片 ImageGetter imageGetter = new ImageGetter() { @Override public Drawable getDrawable(String source) { int id = Integer.parseInt(source); // 根據(jù)id從資源文件中獲取圖片對象 Drawable d = getResources().getDrawable(id); d.setBounds( 0, 0 , d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; tv.append(Html.fromHtml( "<img src='" + R.drawable.log + "'/>" , imageGetter, null )); } Timer timer = new Timer(); TimerTask task_neon = new TimerTask() { public void run() { Message message = new Message(); message.what = 1 ; handler.sendMessage(message); } }; final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1 : // 霓虹燈效果 TextView tv = (TextView) findViewById(R.id.neonlights_effect); String neontext = getString(R.string.neonlights_effect); int len = neontext.length(); int colorsize = colors.length; List <Map<String, Object>> data = new ArrayList<Map<String, Object>> (); for ( int i = 0; i < len; i++ ) { int index = currColor + i; // 顏色索引 if (index >= colorsize) index = index % colorsize; Map <String, Object> target = new HashMap<String, Object> (); target.put( "content", neontext.substring(i, i + 1 )); target.put( "color" , colors[index]); data.add(target); } currColor ++ ; if (currColor == colorsize) currColor = 0 ; tv.setText(SpannableStringBuilderUtils .highlight(neontext, data)); break ; } super .handleMessage(msg); } }; protected void onDestroy() { if (timer != null ) { timer.cancel(); timer = null ; } super .onDestroy(); } }
9>SpannableStringBuilderUtils.java
package com.bravestarr.app.utils; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; /** * @Author BraveStarr * @QQ 1733259520 * @Blog http://www.cnblogs.com/bravestarrhu/ , http://blog.sina.com.cn/wanghubravestarr * * SpannableStringBuilder助手類 */ public class SpannableStringBuilderUtils { /** * 指定內(nèi)容高亮顯示(此方法缺點:變色目標(biāo)文字有多處匹配時效果不好) * @param wholeContent 文本內(nèi)容 * @param data Map<String, Object>數(shù)組包含"content"和"color"字段 * @return * * 如何使用 * * String content = "文本框局部改變顏色" * List<Map<String, Object>> data = new ArrayList<Map<String,Object>>(); Map<String, Object> target = null; target = new HashMap<String, Object>(); target.put("content", "改變");//指定要改變顏色的內(nèi)容 target.put("color", Color.RED);//指定顏色 data.add(target); textview.setText(highlight(content, data)); */ public static SpannableStringBuilder highlight(String wholeContent, List <Map<String, Object>> data) { SpannableStringBuilder spannable = new SpannableStringBuilder( wholeContent); for (Map<String, Object> targetdata : data) { Pattern p = Pattern.compile(targetdata.get("content" ).toString()); Matcher m = p.matcher(wholeContent); while (m.find()) { spannable.setSpan( new ForegroundColorSpan(Integer.valueOf(targetdata.get("color" ).toString())), m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } return spannable; } /** * * @param wholeContent 文本內(nèi)容 * @param data Map<String, Object>數(shù)組包含"start"、"end"和"color"字段 * @return * 如何使用 * * String content = "文本框局部改變顏色" * List<Map<String, Object>> data = new ArrayList<Map<String,Object>>(); Map<String, Object> target = new HashMap<String, Object>(); target.put("start", "5");//指定要改變顏色的起始位置 target.put("end", "7");//指定要改變顏色的結(jié)束位置 target.put("color", Color.RED);//指定顏色 data.add(target); textview.setText(subHighlight(content, data)); */ public static SpannableStringBuilder subHighlight(String wholeContent, List <Map<String, Object>> data) { SpannableStringBuilder spannable = new SpannableStringBuilder( wholeContent); for (Map<String, Object> targetdata : data) { int color = Integer.valueOf(targetdata.get("color" ).toString()); int start = Integer.valueOf(targetdata.get("start" ).toString()); int end = Integer.valueOf(targetdata.get("end" ).toString()); spannable.setSpan( new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); // 設(shè)置指定位置文字的顏色(索引0開始) } return spannable; } }
附件下載:
補(bǔ)充:連續(xù)動畫實現(xiàn),比如一個文本框在屏幕最底部,然后向上冒出,停留一會后,再向下移出屏幕
關(guān)鍵代碼如下:
1.給指定的文本框設(shè)置內(nèi)容(含圖片)
tip = (TextView)findViewById(R.id.tip);
tip.setText(
"按下"
);
ImageGetter imageGetter =
new
ImageGetter() {
@Override
public
Drawable getDrawable(String source) {
int
id = Integer.parseInt(source);
// 根據(jù)id從資源文件中獲取圖片對象
Drawable d = getResources().getDrawable(id);
d.setBounds(
0
,
0
, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return
d;
}
};
tip.append(Html.fromHtml(
"<img src='"
+ R.drawable.back_image +
"'/>"
,
imageGetter,
null
));
tip.append(
"可取消測速并返回選區(qū)界面"
);
|
2.
private TextView tip; private int currStatus;//當(dāng)前狀態(tài), UP , STAY ,或DOWN private static final int UP = 1;//向上移動 狀態(tài) private static final int STAY =2;//停留狀態(tài) private static final int DOWN = 3;//向下移動狀態(tài) private static final int UP_TIME = 2*1000;//向上移動用時 private static final int STAY_TIME = 3*1000;//到達(dá)目標(biāo)后停留 用時 private static final int DOWN_TIME = 2*1000; //向下移動用時 private int time;//(某)動畫的運(yùn)行時間 /** * 更新移動的當(dāng)前狀態(tài) */ private void updateCurrStatus(){ if (currStatus<3 ){ currStatus ++ ; } else { currStatus = 1 ; } } /** * 移動動畫處理 * @param StartX * @param StartY * @param EndX * @param EndY */ private void moveTip( int StartX, int StartY, int EndX, int EndY){ TranslateAnimation translateAnimation = new TranslateAnimation(StartX,EndX,StartY,EndY); translateAnimation.setAnimationListener( new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { updateCurrStatus(); // 在動畫結(jié)束時,重新啟動動畫 switch (currStatus){ case UP: time = STAY_TIME; //此處的68為tip文本框的背景圖的高 moveTip( 0, -68, 0, -68 ); break ; case STAY: time = DOWN_TIME; moveTip( 0, -68, 0, 0 ); break ; case DOWN: break ; } } }); translateAnimation.setDuration(time); tip.startAnimation(translateAnimation); }
3.(onCreate()方法中)啟動動畫時調(diào)用如下代碼
time = UP_TIME;
moveTip(
0
,
0
,
0
,-
68
);<span style=
"color: #000000;"
><span style=
"color: #008000;"
>
//此處的68為tip文本框的背景圖的高</span></span>
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
