Bil*_*ips 27
实际上在ICS中有一个复活节彩蛋闪烁标签!:)我实际上并不建议使用它 - 虽然在源中找到它真的很有趣!
<blink xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm blinking"
/>
</blink>
Run Code Online (Sandbox Code Playgroud)
Cod*_*ile 11
为它创建一个视图动画.您可以在0秒内从100%到0%进行Alpha淡入淡出,然后在一个循环中再次返回.这样,Android就可以处理它,你不必乱用线程和浪费CPU.
有关动画的更多信息,请访问:http:
//developer.android.com/reference/android/view/animation/package-summary.html
教程:http://developerlife.com/tutorials/? p =
343
可以通过添加一个替换两个TextView的ViewFlipper来完成,并且可以在切换时应用Fadein和Fadeout动画.
布局文件:
<ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="wrap_content" android:flipInterval="1000" >
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="TEXT THAT WILL BLINK"/>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="" />
</ViewFlipper>
Run Code Online (Sandbox Code Playgroud)
活动代码:
private ViewFlipper mFlipper;
mFlipper = ((ViewFlipper)findViewById(R.id.flipper));
mFlipper.startFlipping();
mFlipper.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));
Run Code Online (Sandbox Code Playgroud)
在代码中使用线程总是浪费CPU时间并降低应用程序的性能.你不应该一直使用线程.如果需要,请使用.
为此目的使用XML动画:
R.anim.blink
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
Run Code Online (Sandbox Code Playgroud)
眨眼活动:像这样使用它: -
public class BlinkActivity extends Activity implements AnimationListener {
TextView txtMessage;
Button btnStart;
// Animation
Animation animBlink;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
txtMessage = (TextView) findViewById(R.id.txtMessage);
btnStart = (Button) findViewById(R.id.btnStart);
// load the animation
animBlink = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.blink);
// set animation listener
animBlink.setAnimationListener(this);
// button click event
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtMessage.setVisibility(View.VISIBLE);
// start the animation
txtMessage.startAnimation(animBlink);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for blink animation
if (animation == animBlink) {
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
}
Run Code Online (Sandbox Code Playgroud)
如果您有任何疑问,请告诉我..
| 归档时间: |
|
| 查看次数: |
41559 次 |
| 最近记录: |