本文共 3225 字,大约阅读时间需要 10 分钟。
#01# TextView 和 ImageView
TextView和Imageview切换卡顿,为了实现更好的切换,可以用动画来实现,系统自带的TextViewSwitcher 和ImageViewSwitcher,其中设置自定义动画,可以使用如下Demo:
private TextSwitcher mTextSwitcher; @Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.main); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); mTextSwitcher = (TextSwitcher) findViewById(R.id.your_textview); mTextSwitcher.setFactory(new ViewFactory() { @Overridepublic View makeView() {TextView t = new TextView(YourActivity.this);t.setGravity(Gravity.CENTER); //21 Adding eye candy to your ViewGroup’s children return t;}});mTextSwitcher.setInAnimation(in);mTextSwitcher.setOutAnimation(out);}
参考链接:http://developer.android.com/reference/android/widget/TextSwitcher.html
http://developer.android.com/guide/topics/graphics/view-animation.html
#02# 为viewgroup的children添加动画-----LayoutAnimationController
例子是最好的诠释:
mListView = (ListView) findViewById(R.id.my_listview_id);
AnimationSet set = new AnimationSet(true); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(50); set.addAnimation(animation); animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, - 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); set.addAnimation(animation); LayoutAnimationController controller = new LayoutAnimationController( set, 0.5f);Create LayoutAnimationControllerand delay between animations. mListView.setLayoutAnimation(controller);
参考链接:http://developer.android.com/reference/android/view/animation/LayoutAnimationController.html-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#03#
Nine Old Androids 亦可以实现,图片的缩放的效果,跟官方API里面的图片效果一样。即是::Ken Burns特效,
比较详细的Demo,已经有人翻译过了:
:http://blog.csdn.net/manoel/article/details/39164225
一个实现Ken Burns effect图片展示效果的效果android控件。Ken Burns effect是一种图片在切换之前,会缓慢在页面移动或者放大缩小,然后再慢慢切换过去。这样的效果使得每一张静止图片都有动态的效果感觉。类似的效果在,或者在电影视频对静态图片的处理中经常可见。
项目地址
用法:
最简单的用法是直接将项目中提供的jar文件放入,然后在xml中添加:
1 2 3 4 5 | <com.flaviofaria.kenburnsview.KenBurnsView <span id= "1_nwp" style= "width: auto; height: auto; float: none;" ><a id= "1_nwl" href= "" target= "_blank" mpid= "1" style= "text-decoration: none;" ><span style= "color:#0000ff;font-size:14px;width:auto;height:auto;float:none;" >android</span></a></span>:id= "@+id/image" android:layout_width= "match_parent" android:layout_height= "match_parent" android:src= "@drawable/your_drawable" /> |
高级用法:
1.设置listener:
1 2 3 4 5 6 7 8 9 | KenBurnsView kbv = (KenBurnsView) findViewById(R.id.image); kbv.setTransitionListener( new TransitionListener() { @Override public void onTransitionStart(Transition transition) { } @Override public void onTransitionEnd(Transition transition) { } }); |
2.你可以用kbv.pause() 和 kbv.resume()
;暂停和恢复动画。
3.你可以设置动画的插值和过度时间:
1 2 | RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator); kbv.setTransitionGenerator(generator);
|